Example usage for android.view.inputmethod EditorInfo IME_ACTION_DONE

List of usage examples for android.view.inputmethod EditorInfo IME_ACTION_DONE

Introduction

In this page you can find the example usage for android.view.inputmethod EditorInfo IME_ACTION_DONE.

Prototype

int IME_ACTION_DONE

To view the source code for android.view.inputmethod EditorInfo IME_ACTION_DONE.

Click Source Link

Document

Bits of #IME_MASK_ACTION : the action key performs a "done" operation, typically meaning there is nothing more to input and the IME will be closed.

Usage

From source file:org.sufficientlysecure.keychain.ui.dialog.AddEditKeyserverDialogFragment.java

@NonNull
@Override/* ww w .  j a v  a  2  s.co m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    mMessenger = getArguments().getParcelable(ARG_MESSENGER);
    mDialogAction = (DialogAction) getArguments().getSerializable(ARG_ACTION);
    mPosition = getArguments().getInt(ARG_POSITION);

    CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);

    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.add_keyserver_dialog, null);
    alert.setView(view);

    mKeyserverEditText = (EditText) view.findViewById(R.id.keyserver_url_edit_text);
    mKeyserverEditTextLayout = (TextInputLayout) view.findViewById(R.id.keyserver_url_edit_text_layout);
    mKeyserverEditOnionText = (EditText) view.findViewById(R.id.keyserver_onion_edit_text);
    mKeyserverEditOnionTextLayout = (TextInputLayout) view.findViewById(R.id.keyserver_onion_edit_text_layout);
    mVerifyKeyserverCheckBox = (CheckBox) view.findViewById(R.id.verify_connection_checkbox);
    mOnlyTrustedKeyserverCheckBox = (CheckBox) view.findViewById(R.id.only_trusted_keyserver_checkbox);
    mVerifyKeyserverCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mOnlyTrustedKeyserverCheckBox.setEnabled(isChecked);
        }
    });

    switch (mDialogAction) {
    case ADD: {
        alert.setTitle(R.string.add_keyserver_dialog_title);
        break;
    }
    case EDIT: {
        alert.setTitle(R.string.edit_keyserver_dialog_title);
        ParcelableHkpKeyserver keyserver = getArguments().getParcelable(ARG_KEYSERVER);
        mKeyserverEditText.setText(keyserver.getUrl());
        mKeyserverEditOnionText.setText(keyserver.getOnion());
        break;
    }
    }

    // we don't want dialog to be dismissed on click for keyserver addition or edit,
    // thereby requiring the hack seen below and in onStart
    alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            // we need to have an empty listener to prevent errors on some devices as mentioned
            // at http://stackoverflow.com/q/13746412/3000919
            // actual listener set in onStart for adding keyservers or editing them
        }
    });

    alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dismiss();
        }
    });

    switch (mDialogAction) {
    case EDIT: {
        alert.setNeutralButton(R.string.label_keyserver_dialog_delete, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                deleteKeyserver(mPosition);
            }
        });
        break;
    }
    case ADD: {
        // do nothing
        break;
    }
    }

    // Hack to open keyboard.
    // This is the only method that I found to work across all Android versions
    // http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/
    // Notes: * onCreateView can't be used because we want to add buttons to the dialog
    //        * opening in onActivityCreated does not work on Android 4.4
    mKeyserverEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            mKeyserverEditText.post(new Runnable() {
                @Override
                public void run() {
                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(mKeyserverEditText, InputMethodManager.SHOW_IMPLICIT);
                }
            });
        }
    });
    mKeyserverEditText.requestFocus();

    mKeyserverEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
    mKeyserverEditText.setOnEditorActionListener(this);

    return alert.show();
}

From source file:de.azapps.mirakel.new_ui.fragments.TaskFragment.java

private void initTaskNameEdit() {
    taskNameEdit.setText(task.getName());
    // Show Keyboard if stub
    if (task.isStub()) {
        taskNameViewSwitcher.showNext();
        taskNameEdit.selectAll();/* ww  w .j  ava  2s .  co  m*/
        taskNameEdit.requestFocus();
        toggleKeyboard();
    }
    taskNameEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (hasFocus) {
                toggleKeyboard();
            }
        }
    });
    taskNameEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            switch (actionId) {
            case EditorInfo.IME_ACTION_DONE:
            case EditorInfo.IME_ACTION_SEND:
                updateName();
                return true;
            }
            return false;
        }
    });
    taskNameEdit.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(final View v, final int keyCode, final KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                updateName();
                return true;
            }
            return false;
        }
    });
}

From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java

private void populateThirdForm(LinearLayout formLayout) {
    formLayout.addView(createTitle(mContext.getString(R.string.account_create_city_title)));
    EditText cityEditText = createEditText(mContext.getString(R.string.account_create_city_hint),
            InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, CITY_KEY);

    if (mFormData.get(CITY_KEY) != null) {
        cityEditText.setText(mFormData.get(CITY_KEY));
    }//from   w ww  . jav  a 2s  .com

    formLayout.addView(cityEditText);
    formLayout.addView(createErrorView(CITY_KEY));

    formLayout.addView(createTitle(mContext.getString(R.string.account_create_country_title)));

    Spinner spinner = new Spinner(mContext);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    params.bottomMargin = 17;
    spinner.setLayoutParams(params);

    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext,
            android.R.layout.simple_spinner_item, Countries.COUNTRIES);
    spinner.setAdapter(adapter);
    spinner.setPrompt(mContext.getString(R.string.account_create_country_spinner_prompt));
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

            mFormData.put(COUNTRY_KEY, Countries.COUNTRY_CODES[pos]);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    if (mFormData.get(COUNTRY_KEY) != null) {
        List<String> array = Arrays.asList(Countries.COUNTRY_CODES);
        spinner.setSelection(array.indexOf(mFormData.get(COUNTRY_KEY)));
    }

    formLayout.addView(spinner);
}

From source file:com.massivekinetics.ow.ui.views.timepicker.TimePicker.java

public TimePicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // initialization based on locale
    setCurrentLocale(Locale.getDefault());

    // process style attributes
    //TypedArray attributesArray = context.obtainStyledAttributes(
    //        attrs, R.styleable.TimePicker, defStyle, 0);
    //int layoutResourceId = attributesArray.getResourceId(
    //        R.styleable.TimePicker_internalLayout, R.layout.time_picker);
    //attributesArray.recycle();
    int layoutResourceId = R.layout.time_picker_holo;

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(layoutResourceId, this, true);

    // hour//www  .  j a v  a2 s .  c om
    mHourSpinner = (NumberPicker) findViewById(R.id.hour);
    mHourSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        public void onValueChange(NumberPicker spinner, int oldVal, int newVal) {
            updateInputState();
            if (!is24HourView()) {
                if ((oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY)
                        || (oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1)) {
                    mIsAm = !mIsAm;
                    updateAmPmControl();
                }
            }
            onTimeChanged();
        }
    });
    mHourSpinnerInput = (EditText) mHourSpinner.findViewById(R.id.np__numberpicker_input);
    mHourSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);

    // divider (only for the new widget style)
    mDivider = (TextView) findViewById(R.id.divider);
    if (mDivider != null) {
        mDivider.setText(R.string.time_picker_separator);
    }

    // minute
    mMinuteSpinner = (NumberPicker) findViewById(R.id.minute);
    mMinuteSpinner.setMinValue(0);
    mMinuteSpinner.setMaxValue(59);
    mMinuteSpinner.setOnLongPressUpdateInterval(100);
    mMinuteSpinner.setFormatter(NumberPicker.getTwoDigitFormatter());
    mMinuteSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        public void onValueChange(NumberPicker spinner, int oldVal, int newVal) {
            updateInputState();
            int minValue = mMinuteSpinner.getMinValue();
            int maxValue = mMinuteSpinner.getMaxValue();
            if (oldVal == maxValue && newVal == minValue) {
                int newHour = mHourSpinner.getValue() + 1;
                if (!is24HourView() && newHour == HOURS_IN_HALF_DAY) {
                    mIsAm = !mIsAm;
                    updateAmPmControl();
                }
                mHourSpinner.setValue(newHour);
            } else if (oldVal == minValue && newVal == maxValue) {
                int newHour = mHourSpinner.getValue() - 1;
                if (!is24HourView() && newHour == HOURS_IN_HALF_DAY - 1) {
                    mIsAm = !mIsAm;
                    updateAmPmControl();
                }
                mHourSpinner.setValue(newHour);
            }
            onTimeChanged();
        }
    });
    mMinuteSpinnerInput = (EditText) mMinuteSpinner.findViewById(R.id.np__numberpicker_input);
    mMinuteSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);

    /* Get the localized am/pm strings and use them in the spinner */
    mAmPmStrings = new DateFormatSymbols().getAmPmStrings();

    // am/pm
    View amPmView = findViewById(R.id.amPm);
    if (amPmView instanceof Button) {
        mAmPmSpinner = null;
        mAmPmSpinnerInput = null;
        mAmPmButton = (Button) amPmView;
        mAmPmButton.setOnClickListener(new OnClickListener() {
            public void onClick(View button) {
                button.requestFocus();
                mIsAm = !mIsAm;
                updateAmPmControl();
                onTimeChanged();
            }
        });
    } else {
        mAmPmButton = null;
        mAmPmSpinner = (NumberPicker) amPmView;
        mAmPmSpinner.setMinValue(0);
        mAmPmSpinner.setMaxValue(1);
        mAmPmSpinner.setDisplayedValues(mAmPmStrings);
        mAmPmSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                updateInputState();
                picker.requestFocus();
                mIsAm = !mIsAm;
                updateAmPmControl();
                onTimeChanged();
            }
        });
        mAmPmSpinnerInput = (EditText) mAmPmSpinner.findViewById(R.id.np__numberpicker_input);
        mAmPmSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
    }

    // update controls to initial state
    updateHourControl();
    updateAmPmControl();

    setOnTimeChangedListener(NO_OP_CHANGE_LISTENER);

    // set to current time
    setCurrentHour(mTempCalendar.get(Calendar.HOUR_OF_DAY));
    setCurrentMinute(mTempCalendar.get(Calendar.MINUTE));

    if (!isEnabled()) {
        setEnabled(false);
    }

    // set the content descriptions
    setContentDescriptions();

    // If not explicitly specified this view is important for accessibility.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
            && getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
}

From source file:com.fvd.nimbus.BrowseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
    //overridePendingTransition(R.anim.carbon_slide_in,R.anim.carbon_slide_out);
    //overridePendingTransition(R.anim.activity_open_scale,R.anim.activity_close_translate);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    try {//from  w ww .  j  a va  2 s. c om
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    } catch (Exception e) {
        e.printStackTrace();
    }
    clipData = new DataExchange();
    isInitNow = true;
    setContentView(R.layout.screen_browser);
    serverHelper.getInstance().setCallback(this, this);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    lastUrl = prefs.getString("LAST_URL", "");
    saveCSS = prefs.getString("clipStyle", "1").equals("1");
    ctx = this;

    //adapter = new TextAdapter(this);      

    /*Uri data = getIntent().getData();
    if(data!=null){
       lastUrl=data.toString();
    }*/
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    if (Intent.ACTION_VIEW.equals(action) /*&& type != null*/) {
        Uri data = intent.getData();
        if (data != null) {
            lastUrl = data.toString();
            appSettings.appendLog("browse:onCreate  " + lastUrl);
        }
    } else if (Intent.ACTION_SEND.equals(action) /*&& type != null*/) {
        if ("text/plain".equals(type)) {
            String surl = intent.getStringExtra(Intent.EXTRA_TEXT);
            if (surl.contains(" ")) {
                String[] arr = surl.replace("\t", " ").split(" ");
                for (String s : arr) {
                    if (s.contains("://")) {
                        lastUrl = s.trim();
                        break;
                    }
                }
            } else if (surl.contains("://"))
                lastUrl = surl.trim();
            appSettings.appendLog("browse:onCreate  " + lastUrl);
        }
    }

    drawer = (DrawerLayout) findViewById(R.id.root);

    View v = findViewById(R.id.wv);
    wv = (fvdWebView) findViewById(R.id.wv);
    wv.setEventsHandler(this);
    //registerForContextMenu(wv); 
    urlField = (AutoCompleteTextView) findViewById(R.id.etAddess);
    urlField.setSelectAllOnFocus(true);
    urlField.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                /*InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);*/
                onNavButtonClicked();
                return true;
            } else if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                onNavButtonClicked();
                return true;
            }
            return false;
        }
    });
    onViewCreated();

    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case 0:
                findViewById(R.id.bZoomStack).setVisibility(View.VISIBLE);
                findViewById(R.id.bToggleMenu).setVisibility(View.GONE);

                break;

            default:
                break;
            }
        }
    };

    navButton = (ImageButton) findViewById(R.id.ibReloadWebPage);
    navButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //Toast.makeText(getApplicationContext(), "You made a mess", Toast.LENGTH_LONG).show();
            onNavButtonClicked();
        }
    });

    findViewById(R.id.bSavePageFragment).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //toggleTools();
            floatMenu.collapse();
            if (!wv.getInjected())
                Toast.makeText(ctx, getString(R.string.wait_load), Toast.LENGTH_LONG).show();
            clipMode = 2;
            if (wv.getInjected()/* && !v.isSelected()*/) {
                wv.setCanClip(true);
                v.setSelected(true);
                Toast.makeText(ctx, ctx.getString(R.string.use_longtap), Toast.LENGTH_LONG).show();
            }

        }
    });

    (findViewById(R.id.bSaveFullPage)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            floatMenu.collapse();
            if (wv.getInjected()) {
                wv.setCanClip(false);
                wv.saveArticle();
                clipMode = 1;
                progressDialog = ProgressDialog.show(v.getContext(), "Nimbus Clipper",
                        getString(R.string.please_wait), true, false);
            } else {
                Toast.makeText(ctx, getString(R.string.wait_load), Toast.LENGTH_LONG).show();
            }
        }
    });

    findViewById(R.id.bTakeScreenshot).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //toggleTools();
            floatMenu.collapse();
            findViewById(R.id.bSaveFullPage).setVisibility(View.GONE);
            findViewById(R.id.bSavePageFragment).setVisibility(View.GONE);
            findViewById(R.id.bTakeScreenshot).setVisibility(View.GONE);
            if (wv.getInjected()) {
                wv.setCanClip(false);
            }
            findViewById(R.id.bToggleMenu).setVisibility(View.GONE);
            /*screenCapture();
            findViewById(R.id.bToggleMenu).setVisibility(View.VISIBLE);*/

            findViewById(R.id.bTakeScreenshot).postDelayed(new Runnable() {
                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    screenCapture();
                    findViewById(R.id.bToggleMenu).setVisibility(View.VISIBLE);
                    finish();
                }
            }, 10);

            //showDialog(DIALOG_CAPTURE);
        }
    });

    (findViewById(R.id.bDone)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            {
                try {

                    wv.setCanClip(false);
                    wv.endSelectionMode();
                    //findViewById(R.id.bSavePageFragment).setSelected(false);
                    clipMode = 2;
                    wv.endSelectionMode();
                    String selHtml = clipData.getContent();
                    if (selHtml.length() > 0) {
                        String ss = selHtml.substring(0, selHtml.indexOf(">") + 1).toLowerCase();
                        int j = ss.indexOf("<div");
                        if (j == 0) {
                            j = ss.indexOf("style");
                            if (j > 0) {
                                int k = ss.indexOf("\"", j + 11);
                                if (k > 0)
                                    selHtml = selHtml.replace(selHtml.substring(j, k + 1), "");
                            }
                            //selHtml="<DIV>"+selHtml.substring(ss.length());
                        }
                        clipData.setContent(selHtml);
                        clipData.setTitle(wv.getTitle());

                        /*if (true){
                                    
                            if(sessionId.length() == 0 || userPass.length()==0) showSettings();
                            else {
                               if(prefs.getBoolean("check_fast", false)){
                         sendNote(wv.getTitle(), clipData.getContent(), parent, tag);
                         clipData.setContent("");
                               }
                               else {
                               //serverHelper.getInstance().setCallback(this,this);
                               if(appSettings.sessionId.length()>0) {
                         serverHelper.getInstance().sendRequest("notes:getFolders", "","");
                         }
                               }
                            }
                            wv.endSelectionMode();
                         } */

                        Intent i = new Intent(getApplicationContext(), previewActivity.class);
                        i.putExtra("content", clipData);
                        startActivityForResult(i, 5);
                        //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
                        overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
                    }
                    //clipData.setContent("");
                } catch (Exception e) {
                    BugReporter.Send("onEndSelection", e.getMessage());
                }
            }
            //showDialog(DIALOG_CAPTURE);
        }
    });

    findViewById(R.id.bZoomIn).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            wv.ZoomInSelection();
        }
    });

    findViewById(R.id.bZoomOut).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            wv.ZoomOutSelection();
        }
    });

    setNavButtonState(NavButtonState.NBS_GO);

    progressBar = (ProgressBar) findViewById(R.id.progressbar);

    //CookieSyncManager.createInstance(this);

    //webSettings.setLoadsImagesAutomatically(imgOn);
    userMail = prefs.getString("userMail", "");
    userPass = prefs.getString("userPass", "");
    sessionId = prefs.getString("sessionId", "");

    appSettings.sessionId = sessionId;
    appSettings.userMail = userMail;
    appSettings.userPass = userPass;

    if ("1".equals(prefs.getString("userAgent", "1"))) {
        wv.setUserAgent(null);
    } else
        wv.setUserAgent(deskAgent);

    final Activity activity = this;
    //lastUrl="file:///android_asset/android.html";
    if (lastUrl.length() > 0) {
        //wv.navigate(lastUrl);

        //if(!urlField.getText().toString().equals(wv.getUrl()))
        urlField.setText(lastUrl);
        openURL();
    }
    isInitNow = false;

    urlField.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // TODO Auto-generated method stub
            /*String item = (String)parent.getItemAtPosition(position);
                    
            Toast.makeText(
                  getApplicationContext(),
                  "  "
                + item,
                  Toast.LENGTH_SHORT).show();*/
            openURL();

        }
    });

    urlField.addTextChangedListener(this);
    parent = prefs.getString("remFolderId", "default");

    /*ListView listView = (ListView) findViewById(R.id.left_drawer);
    listView.setAdapter(new DrawerMenuAdapter(this,getResources().getStringArray(R.array.lmenu_browser)));
    listView.setOnItemClickListener(this);*/
}

From source file:org.telegram.ui.TwoStepVerificationActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//from w  w  w.j av a2 s.c  om
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                processDone();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));

    ActionBarMenu menu = actionBar.createMenu();
    doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    scrollView = new ScrollView(context);
    scrollView.setFillViewport(true);
    frameLayout.addView(scrollView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) scrollView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    scrollView.setLayoutParams(layoutParams);

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    scrollView.addView(linearLayout);
    ScrollView.LayoutParams layoutParams2 = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
    layoutParams2.width = ScrollView.LayoutParams.MATCH_PARENT;
    layoutParams2.height = ScrollView.LayoutParams.WRAP_CONTENT;
    linearLayout.setLayoutParams(layoutParams2);

    titleTextView = new TextView(context);
    //titleTextView.setTextColor(0xff757575);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
    linearLayout.addView(titleTextView);
    LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) titleTextView.getLayoutParams();
    layoutParams3.width = LayoutHelper.WRAP_CONTENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.gravity = Gravity.CENTER_HORIZONTAL;
    layoutParams3.topMargin = AndroidUtilities.dp(38);
    titleTextView.setLayoutParams(layoutParams3);

    passwordEditText = new EditText(context);
    passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    //passwordEditText.setTextColor(0xff000000);
    passwordEditText.setMaxLines(1);
    passwordEditText.setLines(1);
    passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
    passwordEditText.setSingleLine(true);
    passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordEditText.setTypeface(Typeface.DEFAULT);
    AndroidUtilities.clearCursorDrawable(passwordEditText);
    linearLayout.addView(passwordEditText);
    layoutParams3 = (LinearLayout.LayoutParams) passwordEditText.getLayoutParams();
    layoutParams3.topMargin = AndroidUtilities.dp(32);
    layoutParams3.height = AndroidUtilities.dp(36);
    layoutParams3.leftMargin = AndroidUtilities.dp(40);
    layoutParams3.rightMargin = AndroidUtilities.dp(40);
    layoutParams3.gravity = Gravity.TOP | Gravity.LEFT;
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    passwordEditText.setLayoutParams(layoutParams3);
    passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_NEXT || i == EditorInfo.IME_ACTION_DONE) {
                processDone();
                return true;
            }
            return false;
        }
    });
    passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });

    bottomTextView = new TextView(context);
    //bottomTextView.setTextColor(0xff757575);
    bottomTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    bottomTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    bottomTextView.setText(LocaleController.getString("YourEmailInfo", R.string.YourEmailInfo));
    linearLayout.addView(bottomTextView);
    layoutParams3 = (LinearLayout.LayoutParams) bottomTextView.getLayoutParams();
    layoutParams3.width = LayoutHelper.WRAP_CONTENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
    layoutParams3.topMargin = AndroidUtilities.dp(30);
    layoutParams3.leftMargin = AndroidUtilities.dp(40);
    layoutParams3.rightMargin = AndroidUtilities.dp(40);
    bottomTextView.setLayoutParams(layoutParams3);

    LinearLayout linearLayout2 = new LinearLayout(context);
    linearLayout2.setGravity(Gravity.BOTTOM | Gravity.CENTER_VERTICAL);
    linearLayout.addView(linearLayout2);
    layoutParams3 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = LayoutHelper.MATCH_PARENT;
    linearLayout2.setLayoutParams(layoutParams3);

    bottomButton = new TextView(context);
    bottomButton.setTextColor(0xff4d83b3);
    bottomButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    bottomButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM);
    bottomButton.setText(LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip));
    bottomButton.setPadding(0, AndroidUtilities.dp(10), 0, 0);
    linearLayout2.addView(bottomButton);
    layoutParams3 = (LinearLayout.LayoutParams) bottomButton.getLayoutParams();
    layoutParams3.width = LayoutHelper.WRAP_CONTENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
    layoutParams3.bottomMargin = AndroidUtilities.dp(14);
    layoutParams3.leftMargin = AndroidUtilities.dp(40);
    layoutParams3.rightMargin = AndroidUtilities.dp(40);
    bottomButton.setLayoutParams(layoutParams3);
    bottomButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (type == 0) {
                if (currentPassword.has_recovery) {
                    needShowProgress();
                    TLRPC.TL_auth_requestPasswordRecovery req = new TLRPC.TL_auth_requestPasswordRecovery();
                    ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                        @Override
                        public void run(final TLObject response, final TLRPC.TL_error error) {
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                @Override
                                public void run() {
                                    needHideProgress();
                                    if (error == null) {
                                        final TLRPC.TL_auth_passwordRecovery res = (TLRPC.TL_auth_passwordRecovery) response;
                                        AlertDialog.Builder builder = new AlertDialog.Builder(
                                                getParentActivity());
                                        builder.setMessage(LocaleController.formatString("RestoreEmailSent",
                                                R.string.RestoreEmailSent, res.email_pattern));
                                        builder.setTitle(
                                                LocaleController.getString("AppName", R.string.AppName));
                                        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialogInterface,
                                                            int i) {
                                                        TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(
                                                                1);
                                                        fragment.currentPassword = currentPassword;
                                                        fragment.currentPassword.email_unconfirmed_pattern = res.email_pattern;
                                                        fragment.passwordSetState = 4;
                                                        presentFragment(fragment);
                                                    }
                                                });
                                        Dialog dialog = showDialog(builder.create());
                                        if (dialog != null) {
                                            dialog.setCanceledOnTouchOutside(false);
                                            dialog.setCancelable(false);
                                        }
                                    } else {
                                        if (error.text.startsWith("FLOOD_WAIT")) {
                                            int time = Utilities.parseInt(error.text);
                                            String timeString;
                                            if (time < 60) {
                                                timeString = LocaleController.formatPluralString("Seconds",
                                                        time);
                                            } else {
                                                timeString = LocaleController.formatPluralString("Minutes",
                                                        time / 60);
                                            }
                                            showAlertWithText(
                                                    LocaleController.getString("AppName", R.string.AppName),
                                                    LocaleController.formatString("FloodWaitTime",
                                                            R.string.FloodWaitTime, timeString));
                                        } else {
                                            showAlertWithText(
                                                    LocaleController.getString("AppName", R.string.AppName),
                                                    error.text);
                                        }
                                    }
                                }
                            });
                        }
                    }, ConnectionsManager.RequestFlagFailOnServerErrors
                            | ConnectionsManager.RequestFlagWithoutLogin);
                } else {
                    showAlertWithText(
                            LocaleController.getString("RestorePasswordNoEmailTitle",
                                    R.string.RestorePasswordNoEmailTitle),
                            LocaleController.getString("RestorePasswordNoEmailText",
                                    R.string.RestorePasswordNoEmailText));
                }
            } else {
                if (passwordSetState == 4) {
                    showAlertWithText(
                            LocaleController.getString("RestorePasswordNoEmailTitle",
                                    R.string.RestorePasswordNoEmailTitle),
                            LocaleController.getString("RestoreEmailTroubleText",
                                    R.string.RestoreEmailTroubleText));
                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setMessage(LocaleController.getString("YourEmailSkipWarningText",
                            R.string.YourEmailSkipWarningText));
                    builder.setTitle(
                            LocaleController.getString("YourEmailSkipWarning", R.string.YourEmailSkipWarning));
                    builder.setPositiveButton(
                            LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    email = "";
                                    setNewPassword(false);
                                }
                            });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    showDialog(builder.create());
                }
            }
        }
    });

    if (type == 0) {
        progressView = new FrameLayout(context);
        frameLayout.addView(progressView);
        layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        progressView.setLayoutParams(layoutParams);
        progressView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        ProgressBar progressBar = new ProgressBar(context);
        progressView.addView(progressBar);
        layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER;
        progressView.setLayoutParams(layoutParams);

        listView = new ListView(context);
        listView.setDivider(null);
        listView.setEmptyView(progressView);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == setPasswordRow || i == changePasswordRow) {
                    TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1);
                    fragment.currentPasswordHash = currentPasswordHash;
                    fragment.currentPassword = currentPassword;
                    presentFragment(fragment);
                } else if (i == setRecoveryEmailRow || i == changeRecoveryEmailRow) {
                    TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1);
                    fragment.currentPasswordHash = currentPasswordHash;
                    fragment.currentPassword = currentPassword;
                    fragment.emailOnly = true;
                    fragment.passwordSetState = 3;
                    presentFragment(fragment);
                } else if (i == turnPasswordOffRow || i == abortPasswordRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setMessage(LocaleController.getString("TurnPasswordOffQuestion",
                            R.string.TurnPasswordOffQuestion));
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    setNewPassword(true);
                                }
                            });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    showDialog(builder.create());
                }
            }
        });

        updateRows();

        actionBar.setTitle(LocaleController.getString("TwoStepVerification", R.string.TwoStepVerification));
        titleTextView.setText(
                LocaleController.getString("PleaseEnterCurrentPassword", R.string.PleaseEnterCurrentPassword));
    } else if (type == 1) {
        setPasswordSetState(passwordSetState);
    }

    return fragmentView;
}

From source file:ca.ualberta.cs.drivr.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    userManager.setConnectivityManager((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE));

    /**//from ww w.j a  v  a  2 s  . c o m
     * This calls the login activity a the beginning if there is no local user stored
     */
    if (userManager.getUser().getUsername().isEmpty()) {
        Intent intent = new Intent(MainActivity.this, LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

    context = getApplicationContext();
    PreferenceManager.setDefaultValues(this, R.xml.pref_driver_mode, false);

    setSupportActionBar(toolbar);

    // Create an instance of GoogleAPIClient.
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
    }

    mFragment = (SupportMapFragment) this.getSupportFragmentManager().findFragmentById(R.id.main_map);
    mFragment.getMapAsync(this);

    autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager()
            .findFragmentById(R.id.place_autocomplete_fragment);

    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            ConcretePlace concretePlace = new ConcretePlace(place);
            Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
            if (userManager.getUserMode().equals(UserMode.RIDER)) {
                Intent intent = new Intent(MainActivity.this, NewRequestActivity.class);
                String concretePlaceJson = gson.toJson(concretePlace);
                intent.putExtra(NewRequestActivity.EXTRA_PLACE, concretePlaceJson);
                Log.i(TAG, "Place: " + place.getName() + ", :" + place.getLatLng());
                startActivity(intent);

            } else if (userManager.getUserMode().equals(UserMode.DRIVER)) {
                Intent intent = new Intent(MainActivity.this, SearchRequestActivity.class);
                String concretePlaceJson = gson.toJson(concretePlace);
                intent.putExtra(SearchRequestActivity.EXTRA_PLACE, concretePlaceJson);
                intent.putExtra(SearchRequestActivity.EXTRA_KEYWORD, "");
                Log.i(TAG, "Place: " + place.getName() + ", :" + place.getLatLng());
                startActivity(intent);
            }
        }

        @Override
        public void onError(Status status) {
            // Do nothing
        }
    });

    // Using the floating action button menu system
    final FloatingActionMenu fabMenu = (FloatingActionMenu) findViewById(R.id.main_fab_menu);
    FloatingActionButton fabSettings = (FloatingActionButton) findViewById(R.id.fabSettings);
    FloatingActionButton fabRequests = (FloatingActionButton) findViewById(R.id.main_fab_requests);
    FloatingActionButton fabProfile = (FloatingActionButton) findViewById(R.id.main_fab_profile);
    FloatingActionButton fabHistory = (FloatingActionButton) findViewById(R.id.main_fah_history);
    FloatingActionButton fabLogin = (FloatingActionButton) findViewById(R.id.main_fab_login);
    final FloatingActionButton fabDriver = (FloatingActionButton) findViewById(R.id.main_driver_mode);
    final FloatingActionButton fabRider = (FloatingActionButton) findViewById(R.id.main_rider_mode);

    // Hide the settings FAB
    fabSettings.setVisibility(View.GONE);

    /*
    Change between user and driver mode. Will probably be replaced with an option in settings.
    For now the visibility of this is set to gone because we should not have too many FABs.
    Having too many FABs may cause confusion and rendering issues on small screens.
    */
    keywordEditText = (EditText) findViewById(R.id.main_keyword_edit_text);
    FloatingActionButton fabMode = (FloatingActionButton) findViewById(R.id.main_fab_mode);
    fabMode.setVisibility(View.GONE);
    if (userManager.getUserMode().equals(UserMode.RIDER)) {
        fabRider.setVisibility(View.GONE);
        keywordEditText.setVisibility(View.GONE);
    } else {
        fabDriver.setVisibility(View.GONE);
        keywordEditText.setVisibility(View.VISIBLE);
    }

    keywordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                Intent intent = new Intent(MainActivity.this, SearchRequestActivity.class);
                intent.putExtra(SearchRequestActivity.EXTRA_PLACE, "");
                intent.putExtra(SearchRequestActivity.EXTRA_KEYWORD, keywordEditText.getText().toString());
                keywordEditText.setText("");
                keywordEditText.clearFocus();
                startActivity(intent);
            }
            return true;
        }
    });

    fabMode.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i(TAG, "clicked mode fab");
            /*
            Will be able to implement code below once elasticSearch is up and running
            UserManager userManager = null; // Once elasticSearch is working will replace with finding a User
            if (userManager.getUserMode() == UserMode.DRIVER) {
            userManager.setUserMode(UserMode.RIDER);
            }
            else if (userManager.getUserMode() == UserMode.RIDER) {
            userManager.setUserMode(UserMode.DRIVER);
            //Will have to implement a method "FindNearbyRequests" to get requests whose source
            // is nearby and display it on the map
            //Intent intent = new Intent((MainActivity.this, FindNearbyRequests.class);)
            //startActivity(intent);
            }*/
        }
    });

    fabDriver.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (userManager.getUser().getVehicleDescription().isEmpty()) {
                /*
                * From: http://stackoverflow.com/a/29048271
                * Author: Syeda Zunairah
                * Accessed: November 29, 2016
                * Creates a dialog box with an edit text to get the vehicle description.
                */
                AlertDialog.Builder alert = new AlertDialog.Builder(v.getContext());
                final EditText edittext = new EditText(v.getContext());
                edittext.setText("Vechicle Make");
                edittext.clearComposingText();
                alert.setTitle("Become a Driver!");
                alert.setMessage(
                        "Drivers are require to enter vehicle information!\n\nPlease enter your vehicle's make");

                alert.setView(edittext);

                alert.setPositiveButton("Save Description", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String vehicleDescription = edittext.getText().toString();
                        if (!vehicleDescription.isEmpty()) {
                            userManager.getUser().setVehicleDescription(vehicleDescription);
                            userManager.notifyObservers();
                            userManager.setUserMode(UserMode.DRIVER);
                            ElasticSearch elasticSearch = new ElasticSearch(
                                    userManager.getConnectivityManager());
                            elasticSearch.updateUser(userManager.getUser());
                            keywordEditText.setVisibility(View.VISIBLE);
                            fabDriver.setVisibility(View.GONE);
                            fabRider.setVisibility(View.VISIBLE);
                            fabMenu.close(true);
                        }
                        dialog.dismiss();
                    }
                });

                alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                    }
                });

                AlertDialog newAlert = alert.create();
                newAlert.show();
            }
            if (!userManager.getUser().getVehicleDescription().isEmpty()) {
                userManager.setUserMode(UserMode.DRIVER);
                keywordEditText.setVisibility(View.VISIBLE);
                fabDriver.setVisibility(View.GONE);
                fabRider.setVisibility(View.VISIBLE);
                fabMenu.close(true);
            }
        }
    });

    fabRider.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            userManager.setUserMode(UserMode.RIDER);
            keywordEditText.setVisibility(View.GONE);
            fabRider.setVisibility(View.GONE);
            fabDriver.setVisibility(View.VISIBLE);
            fabMenu.close(true);
        }
    });

    fabLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, LoginActivity.class);
            fabMenu.close(true);
            startActivity(intent);
        }
    });

    fabSettings.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i(TAG, "clicked settings fab");
            Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
            fabMenu.close(true);
            startActivity(intent);
        }
    });

    fabProfile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i(TAG, "clicked profile fab");
            Intent intent = new Intent(MainActivity.this, ProfileActivity.class);
            fabMenu.close(true);
            startActivity(intent);
        }
    });
    fabHistory.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i(TAG, "clicked history fab");
            Intent intent = new Intent(MainActivity.this, RequestHistoryActivity.class);
            fabMenu.close(true);
            startActivity(intent);
        }
    });

    fabRequests.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i(TAG, "clicked requests fab");
            Intent intent = new Intent(MainActivity.this, RequestsListActivity.class);
            fabMenu.close(true);
            startActivity(intent);
        }
    });
    setNotificationAlarm(context);
}

From source file:org.de.jmg.learn.SettingsActivity.java

public void init(boolean blnRestart) throws Exception {
    if (_Intent == null || _main == null || SettingsView == null || _blnInitialized) {
        return;/*from w  w w  . j  a v  a2  s.  c  om*/
    }
    try {
        //lib.ShowToast(_main, "Settings Start");

        RelativeLayout layout = (RelativeLayout) findViewById(R.id.layoutSettings); // id fetch from xml
        ShapeDrawable rectShapeDrawable = new ShapeDrawable(); // pre defined class
        int pxPadding = lib.dpToPx(10);
        rectShapeDrawable.setPadding(pxPadding, pxPadding, pxPadding,
                pxPadding * ((lib.NookSimpleTouch()) ? 2 : 1));
        Paint paint = rectShapeDrawable.getPaint();
        paint.setColor(Color.BLACK);
        paint.setStyle(Style.STROKE);
        paint.setStrokeWidth(5); // you can change the value of 5
        lib.setBg(layout, rectShapeDrawable);

        mainView = _main.findViewById(Window.ID_ANDROID_CONTENT);
        //Thread.setDefaultUncaughtExceptionHandler(ErrorHandler);
        prefs = _main.getPreferences(Context.MODE_PRIVATE);

        TextView txtSettings = (TextView) findViewById(R.id.txtSettings);
        SpannableString Settings = new SpannableString(txtSettings.getText());
        Settings.setSpan(new UnderlineSpan(), 0, Settings.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        txtSettings.setText(Settings);
        initCheckBoxes();
        initSpinners(blnRestart);
        initButtons();
        initHelp();
        edDataDir = (EditText) findViewById(R.id.edDataDir);
        edDataDir.setSingleLine(true);
        edDataDir.setText(_main.JMGDataDirectory);
        edDataDir.setImeOptions(EditorInfo.IME_ACTION_DONE);
        edDataDir.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    String strDataDir = edDataDir.getText().toString();
                    File fileSelected = new File(strDataDir);
                    if (fileSelected.isDirectory() && fileSelected.exists()) {
                        _main.setJMGDataDirectory(fileSelected.getPath());
                        edDataDir.setText(_main.JMGDataDirectory);
                        Editor editor = prefs.edit();
                        editor.putString("JMGDataDirectory", fileSelected.getPath());
                        editor.commit();
                    }
                }
                return true;
            }
        });
        edDataDir.setOnLongClickListener(new OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                ShowDataDirDialog();
                return true;
            }
        });
        if (!(lib.NookSimpleTouch()) && !_main.isSmallDevice) {
            SettingsView.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                        @Override
                        public void onGlobalLayout() {
                            // Ensure you call it only once :
                            lib.removeLayoutListener(SettingsView.getViewTreeObserver(), this);

                            // Here you can get the size :)
                            resize(0);
                            //lib.ShowToast(_main, "Resize End");
                        }
                    });

        } else {
            //resize(1.8f);
            mScale = 1.0f;
        }
        _blnInitialized = true;
    } catch (Exception ex) {
        lib.ShowException(_main, ex);
    }

}

From source file:dev.dworks.apps.asecure.MainActivity.java

private void showLoginDialog() {
    final SharedPreferences.Editor editor = mSharedPreferences.edit();
    final boolean passwordSet = !TextUtils.isEmpty(password);
    final String setPassword = password;

    LayoutInflater layoutInflater = LayoutInflater.from(this);
    final View loginView = layoutInflater.inflate(R.layout.dialog_login, null);
    TextView header = (TextView) loginView.findViewById(R.id.login_header);
    final EditText password = (EditText) loginView.findViewById(R.id.password);
    final EditText password_repeat = (EditText) loginView.findViewById(R.id.password_repeat);

    final Button login = (Button) loginView.findViewById(R.id.login_button);
    //Button cancel = (Button) loginView.findViewById(R.id.cancel_button);

    if (!passwordSet) {
        password_repeat.setVisibility(View.VISIBLE);
        header.setVisibility(View.VISIBLE);
    } else {/*from  w w  w  .  ja v  a 2 s. c  o m*/
        password.setVisibility(View.GONE);
        password_repeat.setVisibility(View.VISIBLE);
        password_repeat.setHint(R.string.login_pwd);
    }
    header.setText(!passwordSet ? getString(R.string.login_message) : getString(R.string.msg_login));

    final Dialog dialog = new Dialog(this, R.style.Theme_Asecure_DailogLogin);
    dialog.setContentView(loginView);
    dialog.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            finish();
        }
    });
    dialog.show();

    password_repeat.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == R.id.login_button || actionId == EditorInfo.IME_NULL
                    || actionId == EditorInfo.IME_ACTION_DONE) {
                login.performClick();
                return true;
            }
            return false;
        }
    });
    login.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (passwordSet) {
                final String passwordString = password_repeat.getText().toString();
                if (TextUtils.isEmpty(passwordString) || passwordString.compareTo(setPassword) != 0) {
                    password_repeat.startAnimation(shake);
                    password_repeat.setError(getString(R.string.msg_wrong_password));
                    return;
                }
            } else {
                final String passwordString = password_repeat.getText().toString();
                final String passwordRepeatString = password_repeat.getText().toString();
                if (TextUtils.isEmpty(passwordString)) {
                    password.startAnimation(shake);
                    password.setError(getString(R.string.msg_pwd_empty));
                    return;
                }
                if (TextUtils.isEmpty(passwordRepeatString)) {
                    password_repeat.startAnimation(shake);
                    password_repeat.setError(getString(R.string.msg_pwd_empty));
                    return;
                } else if (passwordString.compareTo(passwordRepeatString) != 0) {
                    password_repeat.startAnimation(shake);
                    password_repeat.setError(getString(R.string.msg_pwd_dont_match));
                    return;
                }
                editor.putString("LoginPasswordPref", password.getText().toString());
                editor.commit();
            }
            dialog.dismiss();
        }
    });

    /*        cancel.setOnClickListener(new OnClickListener(){
            
             @Override
             public void onClick(View arg0) {
    dialog.dismiss();
    finish();
             }});*/
}

From source file:org.alfresco.mobile.android.application.fragments.node.create.CreateDocumentDialogFragment.java

private View createView(LayoutInflater inflater, ViewGroup container) {
    // Configuration available ?
    ConfigService configService = ConfigManager.getInstance(getActivity()).getConfig(getAccount().getId(),
            ConfigTypeIds.CREATION);/*from  ww  w .jav a 2s .  c  om*/
    if (configService != null) {
        createConfigManager = new CreateConfigManager(getActivity(), configService, (ViewGroup) getRootView());
    }

    View rootView = inflater.inflate(R.layout.sdk_create_content_props, container, false);
    tv = (MaterialEditText) rootView.findViewById(R.id.content_name);
    desc = (MaterialEditText) rootView.findViewById(R.id.content_description);
    tags = (MaterialEditText) rootView.findViewById(R.id.content_tags);
    TextView tsize = (TextView) rootView.findViewById(R.id.content_size);

    if (getArguments().getSerializable(ARGUMENT_CONTENT_FILE) != null) {
        contentFile = (ContentFile) getArguments().getSerializable(ARGUMENT_CONTENT_FILE);
        tempName = contentFile.getFileName();
        tv.setText(tempName);
        tsize.setText(Formatter.formatFileSize(getActivity(), contentFile.getLength()));
        tsize.setVisibility(View.VISIBLE);
    } else {
        tsize.setVisibility(View.GONE);
    }

    tv.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            tempName = tv.getText().toString();
            if (tv.getText().length() == 0) {
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                tv.setError(null);
            } else {
                if (UIUtils.hasInvalidName(tv.getText().toString().trim())) {
                    tv.setError(getString(R.string.filename_error_character));
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                } else {
                    tv.setError(null);
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                    if (!requestInProgress) {
                        Operator.with(getActivity(), getAccount()).load(
                                new RetrieveDocumentNameRequest.Builder(getParent(), tv.getText().toString()));
                        requestCheck = false;
                        requestInProgress = true;
                    } else {
                        requestCheck = true;
                    }
                }
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }
    });

    tags.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (!((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).isEnabled()) {
                return false;
            }
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                createDocument(tv, desc);
                handled = true;
            }
            return handled;
        }
    });

    Folder parentFolder = getParent();

    Operator.with(getActivity(), getAccount())
            .load(new RetrieveDocumentNameRequest.Builder(parentFolder, contentFile.getFileName()));

    // Custom type
    if (createConfigManager != null) {
        DisplayUtils.show(rootView, R.id.types_group);
        Spinner spinner = (Spinner) rootView.findViewById(R.id.types_spinner);
        TypeAdapter adapter = new TypeAdapter(getActivity(), R.layout.row_single_line,
                createConfigManager.retrieveCreationDocumentTypeList());
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                type = (ItemConfig) parent.getItemAtPosition(pos);
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // DO Nothing
            }
        });
        if (adapter.isEmpty()) {
            DisplayUtils.hide(rootView, R.id.types_group);
        }
    } else {
        DisplayUtils.hide(rootView, R.id.types_group);
    }

    return rootView;
}