Ejemplo n.º 1
0
 private void initMaskIcon() {
   if (maskIcon != null) {
     maskIcon.setBounds(0, 0, maskIcon.getIntrinsicHeight(), maskIcon.getIntrinsicHeight());
     final Drawable[] compoundDrawables = getCompoundDrawables();
     setCompoundDrawables(
         compoundDrawables[0], compoundDrawables[1], maskIcon, compoundDrawables[3]);
   }
   super.setOnFocusChangeListener(this);
   super.setOnTouchListener(this);
 }
Ejemplo n.º 2
0
  @Nullable
  @OnClick(R.id.search_layout_btn)
  void onSearchClick() {

    /*关闭键盘*/
    inputMethodManager.hideSoftInputFromWindow(revealRootView.getApplicationWindowToken(), 0);

    if (TextUtils.isEmpty(searchEt.getText().toString())) return;

    ProductKeyListActivity.navigateToProductKeyList(
        SearchActivity.this, searchEt.getText().toString(), searchEt.getText().toString());
    overridePendingTransition(0, 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);
  }
Ejemplo n.º 4
0
  private void setListener() {

    searchEt.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
              /*关闭键盘*/
              inputMethodManager.hideSoftInputFromWindow(
                  revealRootView.getApplicationWindowToken(), 0);

              if (TextUtils.isEmpty(searchEt.getText().toString())) return true;

              ProductKeyListActivity.navigateToProductKeyList(
                  SearchActivity.this,
                  searchEt.getText().toString(),
                  searchEt.getText().toString());
              overridePendingTransition(0, 0);

              return true;
            }
            return false;
          }
        });
  }
  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);
  }
  private ArrayList<UniversalButton> getCurrentUniversalButtons() {
    ArrayList<UniversalButton> buttons = new ArrayList<>();

    for (int i = 0; i < buttonsList.getChildCount(); i++) {
      LinearLayout universalButtonLayout = (LinearLayout) buttonsList.getChildAt(i);

      LinearLayout nameLayout = (LinearLayout) universalButtonLayout.getChildAt(0);
      AppCompatEditText nameEditText = (AppCompatEditText) nameLayout.getChildAt(0);
      AppCompatEditText signalEditText = (AppCompatEditText) universalButtonLayout.getChildAt(1);

      buttons.add(
          new UniversalButton(
              null, nameEditText.getText().toString(), null, signalEditText.getText().toString()));
    }

    return buttons;
  }
Ejemplo n.º 7
0
  /** *** CHECK FOR EMPTY FIELDS **** */
  private void checkEmpty() {

    /* HIDE THE KEYBOARD */
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edtDishName.getWindowToken(), 0);

    /** GET THE REQUIRED DATA * */
    MEAL_NAME = edtDishName.getText().toString();
    MEAL_DESCRIPTION = edtDishDescription.getText().toString();
    MEAL_PRICE = edtDishPrice.getText().toString();

    if (MEAL_NAME.length() == 0) {
      inputDishName.setError("Menu / Dish name cannot be empty!");
      edtDishName.requestFocus();
    } else if (MEAL_DESCRIPTION.length() == 0) {
      inputDishDescription.setError("Please provide the Menu / Dish Description");
      edtDishDescription.requestFocus();
    } else if (MEAL_PRICE.length() == 0) {
      inputDishPrice.setError("The Menu / Dish needs to have a Price");
      edtDishPrice.requestFocus();
    } else {
      /* REMOVE THE ERRORS (IF SHOWN) */
      inputDishName.setErrorEnabled(false);
      inputDishDescription.setErrorEnabled(false);
      inputDishPrice.setErrorEnabled(false);

      /* CHECK FOR UNIQUE MENU / DISH NAME */
      new checkUniqueDishName().execute();
    }
  }
Ejemplo n.º 8
0
  @Override
  public void onSaveInstanceState(Bundle savedInstanceState) {
    // Save state
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState.putInt(REPORT_ID, targetId);
    savedInstanceState.putInt(REPORT_TYPE, type);
    savedInstanceState.putInt(REPORT_CATEGORY, reportCategorySelect.getCheckedRadioButtonId());

    if (targetName != null) {
      savedInstanceState.putString(REPORT_USER, targetName);
    }
    if (reportContent != null) {
      savedInstanceState.putString(REPORT_CONTENT, reportContent.getText().toString());
    }
  }
  private void set(Alarm alarm, TimerObj timer, String tag) {
    String label = mLabelBox.getText().toString();
    if (label.trim().isEmpty()) {
      // Don't allow user to input label with only whitespace.
      label = "";
    }

    if (alarm != null) {
      set(alarm, tag, label);
    } else if (timer != null) {
      set(timer, tag, label);
    } else {
      LogUtils.e("No alarm or timer available.");
    }
  }
Ejemplo n.º 10
0
  @Override
  public void setInputType(int type) {
    if (type == -1) {
      type = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_PASSWORD;
    }

    if (type == InputType.TYPE_CLASS_NUMBER
        || type == InputType.TYPE_NUMBER_FLAG_SIGNED
        || type == InputType.TYPE_NUMBER_FLAG_DECIMAL
        || type == InputType.TYPE_CLASS_PHONE) {
      final String symbolExceptions = getSymbolExceptions();
      this.setKeyListener(DigitsKeyListener.getInstance("0123456789." + symbolExceptions));
    } else {
      super.setInputType(type);
    }
  }
Ejemplo n.º 11
0
  /** Wrapper for sending the report to NS servers. */
  private void startSendReport() {
    if (isFinishing()) {
      return;
    }

    String reportText = reportContent.getText().toString();
    if (reportText.length() <= 0) {
      SparkleHelper.makeSnackbar(view, getString(R.string.report_blank));
      return;
    }

    AlertDialog.Builder dialogBuilder =
        new AlertDialog.Builder(this, RaraHelper.getThemeMaterialDialog(this));
    dialogBuilder
        .setTitle(R.string.report_confirm)
        .setPositiveButton(R.string.report_send_confirm, dialogListener)
        .setNegativeButton(R.string.explore_negative, null)
        .show();
  }
Ejemplo n.º 12
0
  /** *** CHECK FOR NECESSARY DETAILS **** */
  private void checkCatDetails() {

    /* HIDE THE KEYBOARD */
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edtCategoryName.getWindowToken(), 0);

    /** CHECK THAT THE CATEGORY NAME AND THE CATEGORY THUMB ARE NOT EMPTY * */
    if (edtCategoryName.getText().toString().length() == 0 && CATEGORY_THUMB == null) {
      edtCategoryName.setError("You need to enter the Category Name");
      String strMessage = "An image representing the Category is necessary to save it!";
      Toast.makeText(getApplicationContext(), strMessage, Toast.LENGTH_SHORT).show();
    } else if (edtCategoryName.getText().toString().length() == 0 && CATEGORY_THUMB != null) {
      edtCategoryName.setError("You need to enter the Category Name");
    } else if (edtCategoryName.getText().toString().length() != 0 && CATEGORY_THUMB == null) {
      String strMessage = "An image representing the Category is necessary to save it!";
      Toast.makeText(getApplicationContext(), strMessage, Toast.LENGTH_SHORT).show();
    } else {
      /** *** CHECK FOR UNIQUE MEAL CATEGORY **** */
      new checkUniqueCategory().execute();
    }
  }
Ejemplo n.º 13
0
  private void sendReport() {
    if (isInProgress) {
      SparkleHelper.makeSnackbar(view, getString(R.string.multiple_request_error));
      return;
    }
    isInProgress = true;

    String typeHeader;
    String reasonHeader;
    switch (type) {
      case REPORT_TYPE_RMB:
        typeHeader = getString(R.string.report_header_rmb_post);
        reasonHeader = getString(R.string.report_header_reason);
        break;
      case REPORT_TYPE_TELEGRAM:
        typeHeader = getString(R.string.report_header_telegram);
        reasonHeader = getString(R.string.report_header_reason);
        break;
      case REPORT_TYPE_TASK:
        typeHeader = getString(R.string.report_header_task);
        reasonHeader = getString(R.string.report_header_response);
        break;
      default:
        typeHeader = "";
        reasonHeader = "";
        break;
    }
    final String commentHeader =
        String.format(
            Locale.US,
            getString(R.string.report_header_comment_template),
            typeHeader,
            targetId,
            reasonHeader,
            reportContent.getText().toString());

    final int problemHeader;
    if (type == REPORT_TYPE_TASK) {
      problemHeader = HEADER_GHR_MODREPLY;
    } else {
      switch (reportCategorySelect.getCheckedRadioButtonId()) {
        case R.id.report_inappropriate:
          problemHeader = HEADER_GHR_INAPPROPRIATE;
          break;
        case R.id.report_spam:
          problemHeader = HEADER_GHR_SPAMMER;
          break;
        default:
          problemHeader = HEADER_GHR_OTHER;
          break;
      }
    }

    NSStringRequest stringRequest =
        new NSStringRequest(
            getApplicationContext(),
            Request.Method.POST,
            REPORT_URL,
            new Response.Listener<String>() {
              @Override
              public void onResponse(String response) {
                isInProgress = false;
                mSwipeRefreshLayout.setRefreshing(false);
                finish();
              }
            },
            new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                SparkleHelper.logError(error.toString());
                mSwipeRefreshLayout.setRefreshing(false);
                isInProgress = false;
                if (error instanceof TimeoutError
                    || error instanceof NoConnectionError
                    || error instanceof NetworkError) {
                  SparkleHelper.makeSnackbar(view, getString(R.string.login_error_no_internet));
                } else {
                  SparkleHelper.makeSnackbar(view, getString(R.string.login_error_generic));
                }
              }
            });

    Map<String, String> params = new HashMap<String, String>();
    params.put("problem", Integer.toString(problemHeader));
    params.put("comment", SparkleHelper.escapeHtml(commentHeader));
    params.put("submit", "1");
    stringRequest.setParams(params);

    if (!DashHelper.getInstance(this).addRequest(stringRequest)) {
      mSwipeRefreshLayout.setRefreshing(false);
      isInProgress = false;
      SparkleHelper.makeSnackbar(view, getString(R.string.rate_limit_error));
    }
  }
Ejemplo n.º 14
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    myOnAttach(getActivity());

    final StudentsAdapter studentsAdapter = new StudentsAdapter(students, getActivity());
    RecyclerView recyclerView = (RecyclerView) getActivity().findViewById(R.id.recyclerView);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(studentsAdapter);
    getActivity().findViewById(R.id.progressBar).setVisibility(View.GONE);
    getActivity().findViewById(R.id.no_result).setVisibility(View.GONE);
    getActivity().findViewById(R.id.recyclerView).setVisibility(View.VISIBLE);

    final AppCompatEditText skillsEdit =
        (AppCompatEditText) getActivity().findViewById(R.id.skills);
    skillsEdit.setImeOptions(EditorInfo.IME_ACTION_DONE);

    getActivity()
        .findViewById(R.id.searchButton)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                String text = skillsEdit.getText().toString().trim();
                ArrayList<String> words = getWordsFromText(text);

                hideSoftKeyboard();

                getActivity().findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
                getActivity().findViewById(R.id.no_result).setVisibility(View.GONE);
                getActivity().findViewById(R.id.recyclerView).setVisibility(View.GONE);
                User.searchStudentsBySkills(
                    getActivity(),
                    words,
                    new User.OnUsersDownloadedCallback() {
                      @Override
                      public void onUsersDownloaded(List<User> users) {
                        getActivity().findViewById(R.id.progressBar).setVisibility(View.GONE);
                        if (users == null || users.size() == 0) {
                          getActivity().findViewById(R.id.no_result).setVisibility(View.VISIBLE);
                        } else {
                          getActivity().findViewById(R.id.recyclerView).setVisibility(View.VISIBLE);
                          students.clear();
                          students.addAll(users);
                          sortUsers();
                          studentsAdapter.setUsers(students);
                          studentsAdapter.notifyDataSetChanged();
                        }
                      }
                    });
              }
            });

    skillsEdit.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_DONE) {
              getActivity().findViewById(R.id.searchButton).performClick();
              handled = true;
            }

            return handled;
          }
        });
  }
Ejemplo n.º 15
0
 @Override
 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
   super.onFocusChanged(focused, direction, previouslyFocusedRect);
   setClearIconVisible(focused && length() > 0);
 }
Ejemplo n.º 16
0
 @Override
 protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
   super.onTextChanged(text, start, lengthBefore, lengthAfter);
   setClearIconVisible(hasFocus() && text.length() > 0);
 }
Ejemplo n.º 17
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_report);

    // Either get data from intent or restore state
    if (getIntent() != null) {
      if (getIntent().getData() != null) {
        targetId = Integer.valueOf(getIntent().getData().getHost());
        type = REPORT_TYPE_TASK;
      } else {
        targetId = getIntent().getIntExtra(REPORT_ID, 0);
        targetName = SparkleHelper.getNameFromId(getIntent().getStringExtra(REPORT_USER));
        type = getIntent().getIntExtra(REPORT_TYPE, REPORT_TYPE_TASK);
      }
    }
    if (savedInstanceState != null) {
      targetId = savedInstanceState.getInt(REPORT_ID);
      targetName = savedInstanceState.getString(REPORT_USER);
      type = savedInstanceState.getInt(REPORT_TYPE);
      categoryHolder = savedInstanceState.getInt(REPORT_CATEGORY, CATEGORY_NONE);
      contentHolder = savedInstanceState.getString(REPORT_CONTENT);
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_report);
    setToolbar(toolbar);

    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.report_refresher);
    mSwipeRefreshLayout.setColorSchemeResources(RaraHelper.getThemeRefreshColours(this));
    mSwipeRefreshLayout.setEnabled(false);

    dialogListener =
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            mSwipeRefreshLayout.post(
                new Runnable() {
                  @Override
                  public void run() {
                    mSwipeRefreshLayout.setRefreshing(true);
                    sendReport();
                  }
                });
          }
        };

    view = findViewById(R.id.report_main);
    targetHolder = (RelativeLayout) findViewById(R.id.report_target_holder);
    reportTarget = (TextView) findViewById(R.id.report_target);
    reportCategoryHolder = (CardView) findViewById(R.id.report_category_holder);
    reportCategorySelect = (RadioGroup) findViewById(R.id.report_category);
    reportContent = (AppCompatEditText) findViewById(R.id.report_content);

    targetHolder.setVisibility(View.VISIBLE);
    reportCategoryHolder.setVisibility(View.VISIBLE);

    // If replying to mod mail, use this message instead
    if (type == REPORT_TYPE_TASK) {
      reportTarget.setText(
          String.format(Locale.US, getString(R.string.report_mod_reply), targetId));
      reportCategoryHolder.setVisibility(View.GONE);
    } else {
      String reportType = "";
      switch (type) {
        case REPORT_TYPE_RMB:
          reportType = getString(R.string.report_rmb_post);
          break;
        case REPORT_TYPE_TELEGRAM:
          reportType = getString(R.string.report_telegram);
          break;
        default:
          targetHolder.setVisibility(View.GONE);
          break;
      }
      reportTarget.setText(
          String.format(
              Locale.US, getString(R.string.report_target), reportType, targetId, targetName));
    }

    if (categoryHolder != CATEGORY_NONE) {
      reportCategorySelect.check(categoryHolder);
    }

    if (contentHolder != null && contentHolder.length() > 0) {
      reportContent.setText(contentHolder);
    }
  }
Ejemplo n.º 18
0
  private void validateData() {

    /** HIDE THE KEYBOARD * */
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);

    /** * GRAB THE DATA ** */
    TAX_NAME = edtTaxName.getText().toString();
    TAX_PERCENTAGE = edtTaxPercentage.getText().toString();
    TAX_REGISTRATION = edtTaxRegistration.getText().toString();
    if (TAX_COMPLETE_AMOUNT) {
      TAX_PERCENT_OF_AMOUNT = "100";
    } else {
      TAX_PERCENT_OF_AMOUNT = edtTaxPercentageOfAmount.getText().toString();
    }

    /** *** CHECK FOR THE REQUIRED DATA **** */
    if (edtTaxName.getText().toString().length() == 0) {
      edtTaxName.setError(getResources().getString(R.string.tax_creator_tax_name_empty));
      edtTaxName.requestFocus();
    } else if (edtTaxPercentage.getText().toString().length() == 0) {
      edtTaxPercentage.setError(
          getResources().getString(R.string.tax_creator_tax_percentage_empty));
      edtTaxPercentage.requestFocus();
    } else if (edtTaxPercentage.getText().toString().equals("0")
        || edtTaxPercentage.getText().toString().equals("0.0")
        || edtTaxPercentage.getText().toString().equals("0.00")) {
      edtTaxPercentage.setError(getResources().getString(R.string.tax_creator_tax_percentage_zero));
      edtTaxPercentage.requestFocus();
    } else if (edtTaxRegistration.getText().toString().length() == 0) {
      edtTaxRegistration.setError(
          getResources().getString(R.string.tax_creator_tax_registration_empty));
      edtTaxRegistration.requestFocus();
    } else if (!TAX_COMPLETE_AMOUNT
        && edtTaxPercentageOfAmount.getText().toString().length() == 0) {
      edtTaxPercentageOfAmount.setError(
          getResources().getString(R.string.tax_creator_tax_percentage_of_amount_empty));
      edtTaxPercentageOfAmount.requestFocus();
    } else if (edtTaxPercentageOfAmount.getText().toString().equals("0")
        || edtTaxPercentageOfAmount.getText().toString().equals("0.0")
        || edtTaxPercentageOfAmount.getText().toString().equals("0.00")) {
      edtTaxPercentageOfAmount.setError(
          getResources().getString(R.string.tax_creator_tax_percentage_of_amount_zero));
      edtTaxPercentageOfAmount.requestFocus();
    } else {
      /** CHECK FOR UNIQUE TAX NAME * */
      new checkUniqueTaxName().execute();
    }
  }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Bundle bundle = getArguments();
    final Alarm alarm = bundle.getParcelable(KEY_ALARM);
    final TimerObj timer = bundle.getParcelable(KEY_TIMER);
    final String tag = bundle.getString(KEY_TAG);
    final String label =
        savedInstanceState != null
            ? savedInstanceState.getString(KEY_LABEL)
            : bundle.getString(KEY_LABEL);

    final Context context = getActivity();
    final int colorAccent = Utils.obtainStyledColor(context, R.attr.colorAccent, Color.RED);
    final int colorControlNormal =
        Utils.obtainStyledColor(context, R.attr.colorControlNormal, Color.WHITE);

    mLabelBox = new AppCompatEditText(context);
    mLabelBox.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
              set(alarm, timer, tag);
              return true;
            }
            return false;
          }
        });
    mLabelBox.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) {
            final int color = TextUtils.isEmpty(s) ? colorControlNormal : colorAccent;
            mLabelBox.setSupportBackgroundTintList(ColorStateList.valueOf(color));
          }

          @Override
          public void afterTextChanged(Editable editable) {}
        });
    mLabelBox.setText(label);
    mLabelBox.selectAll();

    final int padding = getResources().getDimensionPixelSize(R.dimen.label_edittext_padding);
    final AlertDialog alertDialog =
        new AlertDialog.Builder(context)
            .setView(mLabelBox, padding, 0, padding, 0)
            .setPositiveButton(
                R.string.time_picker_set,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    set(alarm, timer, tag);
                  }
                })
            .setNegativeButton(
                R.string.time_picker_cancel,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                  }
                })
            .setMessage(R.string.label)
            .create();

    alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    return alertDialog;
  }
 @Override
 public void onSaveInstanceState(@NonNull Bundle outState) {
   super.onSaveInstanceState(outState);
   outState.putString(KEY_LABEL, mLabelBox.getText().toString());
 }
Ejemplo n.º 21
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();
  }
Ejemplo n.º 22
0
  private void handleRegisterRequest() {
    final String auth = mEtRegisterAuth.getText().toString().trim();
    final String psw = mEtRegisterPsw.getText().toString().trim();
    final String nick = mEtRegisterName.getText().toString().trim();
    if (TextUtils.isEmpty(auth)) {
      showShortToast("验证码不能为空");
      return;
    }
    if (TextUtils.isEmpty(psw)) {
      showShortToast("密码不能为空");
      return;
    }
    if (TextUtils.isEmpty(nick)) {
      showShortToast("昵称不能为空");
      return;
    }
    OkHttpClientManager.Param[] params =
        new OkHttpClientManager.Param[] {
          new OkHttpClientManager.Param("userPhone", phone),
          new OkHttpClientManager.Param("smsCodeKey", auth),
          new OkHttpClientManager.Param("loginPassword", psw),
          new OkHttpClientManager.Param("device", "2"),
          new OkHttpClientManager.Param("deviceVersion", android.os.Build.VERSION.RELEASE),
          new OkHttpClientManager.Param("model", android.os.Build.MODEL),
          new OkHttpClientManager.Param("imei", TDevice.getDeviceId(this)),
          new OkHttpClientManager.Param("userNike", nick),
          new OkHttpClientManager.Param("applicationVersion", TDevice.getVersionName())
        };
    OkHttpClientManager.postAsyn(
        Constants.LoginAndRegister.REGISTER,
        params,
        new OkHttpClientManager.ResultCallback<RegisterModel>() {
          @Override
          public void onError(Request request, Exception e) {
            e.printStackTrace();
            showShortToast("请检查网络");
          }

          @Override
          public void onResponse(RegisterModel us) {
            Log.e("TAG", us.toString());
            showShortToast(us.getResultMsg());
            if (us.getStatusCode() == 200) {
              // Sp数据保存
              BaseApplication.token = us.getTokenId();

              SPCache.putString(Constants.SharePreference.USER_TOKEN, us.getTokenId());
              SPCache.putInt(Constants.SharePreference.USER_STATUS, us.getData().getUserStatus());
              SPCache.putString(
                  Constants.SharePreference.USER_HEAD_IMAGE, us.getData().getUserSmallHeadImgUrl());
              SPCache.putString(Constants.SharePreference.USER_NICK, us.getData().getUserNick());
              SPCache.putString(
                  Constants.SharePreference.USER_PROFESSION, us.getData().getUserProfession());
              SPCache.putString(Constants.SharePreference.USER_PHONE, us.getData().getUserPhone());
              SPCache.putString(Constants.SharePreference.USER_SEX, us.getData().getUserSex());
              SPCache.putString(
                  Constants.SharePreference.USER_BIRTHDAY, us.getData().getUserBirthday());
              Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
              startActivity(intent);
              finish();
            }
          }
        });
  }