public void shEditDialog(final String key, String title, int msg) {
    Resources res = context.getResources();
    String cancel = res.getString(R.string.cancel);
    String ok = res.getString(R.string.ps_volt_save);

    LayoutInflater factory = LayoutInflater.from(context);
    final View alphaDialog = factory.inflate(R.layout.sh_dialog, null);

    settingText = (EditText) alphaDialog.findViewById(R.id.shText);
    settingText.setHint(msg);
    settingText.setText(mPreferences.getString(key, ""));
    settingText.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            return true;
          }
        });

    settingText.addTextChangedListener(
        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) {}
        });
    new AlertDialog.Builder(context)
        .setTitle(title)
        .setView(alphaDialog)
        .setNegativeButton(
            cancel,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                /* nothing */
              }
            })
        .setPositiveButton(
            ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                final SharedPreferences.Editor editor = mPreferences.edit();
                editor.putString(key, settingText.getText().toString()).commit();
              }
            })
        .create()
        .show();
  }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   View v = convertView;
   if (v == null) {
     LayoutInflater vi =
         (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     v = vi.inflate(R.layout.row, null);
   }
   Message m = items.get(position);
   // if (m != null) {
   m.createColorFromString(m.from);
   TextView tt = (TextView) v.findViewById(R.id.username);
   TextView bt = (TextView) v.findViewById(R.id.message);
   if (isMonospaced) {
     tt.setTypeface(Typeface.MONOSPACE);
     bt.setTypeface(Typeface.MONOSPACE);
   }
   tt.setText(m.getFrom());
   tt.setTextColor(m.color);
   bt.setText(m.getMessage());
   // }
   return v;
 }
Example #3
0
  public void openDialog(
      String title,
      final int min,
      final int max,
      final Preference pref,
      final String path,
      final String key) {
    Resources res = context.getResources();
    String cancel = res.getString(R.string.cancel);
    String ok = res.getString(R.string.ok);
    final EditText settingText;
    LayoutInflater factory = LayoutInflater.from(context);
    final View alphaDialog = factory.inflate(R.layout.seekbar_dialog, null);

    final SeekBar seekbar = (SeekBar) alphaDialog.findViewById(R.id.seek_bar);
    seekbar.setMax(max - min);

    int currentProgress = min;
    if (key.equals("pref_viber")) {
      currentProgress = Integer.parseInt(Helpers.readOneLine(path));
    } else {
      currentProgress = Integer.parseInt(vib.get_val(path));
    }
    if (currentProgress > max) currentProgress = max - min;
    else if (currentProgress < min) currentProgress = 0;
    else currentProgress = currentProgress - min;

    seekbar.setProgress(currentProgress);

    settingText = (EditText) alphaDialog.findViewById(R.id.setting_text);
    settingText.setText(Integer.toString(currentProgress + min));

    settingText.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
              int val = Integer.parseInt(settingText.getText().toString()) - min;
              seekbar.setProgress(val);
              return true;
            }
            return false;
          }
        });

    settingText.addTextChangedListener(
        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) {
            try {
              int val = Integer.parseInt(s.toString());
              if (val > max) {
                s.replace(0, s.length(), Integer.toString(max));
                val = max;
              }
              seekbar.setProgress(val - min);
            } catch (NumberFormatException ex) {
            }
          }
        });

    OnSeekBarChangeListener seekBarChangeListener =
        new OnSeekBarChangeListener() {
          @Override
          public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) {
            final int mSeekbarProgress = seekbar.getProgress();
            if (fromUser) {
              settingText.setText(Integer.toString(mSeekbarProgress + min));
            }
          }

          @Override
          public void onStopTrackingTouch(SeekBar seekbar) {}

          @Override
          public void onStartTrackingTouch(SeekBar seekbar) {}
        };
    seekbar.setOnSeekBarChangeListener(seekBarChangeListener);

    new AlertDialog.Builder(context)
        .setTitle(title)
        .setView(alphaDialog)
        .setNegativeButton(
            cancel,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                // nothing
              }
            })
        .setPositiveButton(
            ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                int val = min;
                if (!settingText.getText().toString().equals(""))
                  val = Integer.parseInt(settingText.getText().toString());
                if (val < min) val = min;
                seekbar.setProgress(val - min);
                int newProgress = seekbar.getProgress() + min;
                new CMDProcessor()
                    .su.runWaitFor("busybox echo " + Integer.toString(newProgress) + " > " + path);
                String v;
                if (key.equals("pref_viber")) {
                  v = vib.get_val(path);
                  Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                  vb.vibrate(1000);
                } else {
                  v = Helpers.readOneLine(path);
                }
                final SharedPreferences.Editor editor = mPreferences.edit();
                editor.putInt(key, Integer.parseInt(v)).commit();
                pref.setSummary(v);
              }
            })
        .create()
        .show();
  }
Example #4
0
 public static String visualize(View view) {
   Canvas canvas = new Canvas();
   view.draw(canvas);
   return shadowOf(canvas).getDescription();
 }