private void addUniversalButtonLayoutToDialogView(String name, String signal) {
    TextWatcher tw =
        new TextWatcher() {
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}

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

          @Override
          public void afterTextChanged(Editable s) {
            sendChannelDetailsChangedBroadcast(
                getActivity(), null, 0, null, -1, getCurrentUniversalButtons());
          }
        };
    LinearLayout newUniversalButtonLayout = new LinearLayout(getActivity());
    newUniversalButtonLayout.setOrientation(LinearLayout.VERTICAL);

    LinearLayout nameLayout = new LinearLayout(getActivity());
    nameLayout.setOrientation(LinearLayout.HORIZONTAL);

    AppCompatEditText universalButtonNameEditText = new AppCompatEditText(getActivity());
    universalButtonNameEditText.setHint(R.string.name);
    universalButtonNameEditText.setText(name);
    universalButtonNameEditText.addTextChangedListener(tw);

    ImageButton deleteUniversalButton = new ImageButton(getActivity());
    deleteUniversalButton.setBackgroundResource(android.R.color.transparent);
    deleteUniversalButton.setImageResource(android.R.drawable.ic_menu_delete);
    deleteUniversalButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            buttonsList.removeView((View) v.getParent().getParent());
            sendChannelDetailsChangedBroadcast(
                getActivity(), null, 0, null, -1, getCurrentUniversalButtons());
          }
        });

    nameLayout.addView(
        universalButtonNameEditText,
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f));
    nameLayout.addView(deleteUniversalButton);

    AppCompatEditText universalButtonSignalEditText = new AppCompatEditText(getActivity());
    universalButtonSignalEditText.setHint(R.string.enter_network_signal);
    universalButtonSignalEditText.setText(signal);
    universalButtonSignalEditText.addTextChangedListener(tw);

    newUniversalButtonLayout.addView(nameLayout);
    newUniversalButtonLayout.addView(universalButtonSignalEditText);

    buttonsList.addView(newUniversalButtonLayout);
  }
コード例 #2
0
  public MaterialEditText(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
    int[] attrSet = new int[] {android.R.attr.hint};
    TypedArray a = context.obtainStyledAttributes(attrs, attrSet, 0, 0);
    String hint = a.getString(0);
    a.recycle();
    if (hint != null) this.setHint(hint);

    AppCompatEditText editor = new AppCompatEditText(context, attrs);
    this.addView(editor);
    editor.setHint("");
    editor.setId(android.R.id.text1);
  }
コード例 #3
0
  private void backupDialog(final Backup.PARTITION partition_type) {
    LinearLayout layout = new LinearLayout(getActivity());
    layout.setPadding(30, 30, 30, 30);

    final AppCompatEditText editText = new AppCompatEditText(getActivity());
    editText.setTextColor(
        getResources().getColor(Utils.DARKTHEME ? R.color.textcolor_dark : R.color.black));
    editText.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    if (partition_type == Backup.PARTITION.BOOT) editText.setText(RootUtils.getKernelVersion());
    editText.setHint(getString(R.string.name));

    layout.addView(editText);

    new AlertDialog.Builder(getActivity())
        .setView(layout)
        .setNegativeButton(
            getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {}
            })
        .setPositiveButton(
            getString(R.string.ok),
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                final String name = editText.getText().toString().trim();
                if (name.isEmpty()) {
                  Utils.toast(getString(R.string.empty_name), getActivity());
                  return;
                }

                File file = null;
                switch (partition_type) {
                  case BOOT:
                    file = boot;
                    break;
                  case RECOVERY:
                    file = recovery;
                    break;
                  case FOTA:
                    file = fota;
                    break;
                }
                if (file != null && new File(file.toString() + "/" + name + ".img").exists()) {
                  Utils.toast(getString(R.string.backup_already_exists), getActivity());
                  return;
                }

                new AsyncTask<Void, Void, Void>() {
                  private ProgressDialog progressDialog;

                  @Override
                  protected void onPreExecute() {
                    super.onPreExecute();
                    progressDialog = new ProgressDialog(getActivity());
                    progressDialog.setMessage(getString(R.string.backing_up));
                    progressDialog.setCancelable(false);
                    progressDialog.show();
                  }

                  @Override
                  protected Void doInBackground(Void... params) {
                    Backup.backup(name, partition_type);
                    return null;
                  }

                  @Override
                  protected void onPostExecute(Void aVoid) {
                    super.onPostExecute(aVoid);
                    getHandler()
                        .post(
                            new Runnable() {
                              @Override
                              public void run() {
                                create();
                                progressDialog.dismiss();
                              }
                            });
                  }
                }.execute();
              }
            })
        .show();
  }