예제 #1
0
  private View createCheckBox(ViewGroup parent, MethodInfo methodInfo) {
    final Method method = methodInfo.getMethod();
    final Object instance = methodInfo.getInstance();
    final Context context = parent.getContext();

    View view = inflater.inflate(R.layout.item_settings_checkbox, parent, false);
    ((TextView) view.findViewById(R.id.title)).setText(methodInfo.getTitle());
    CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
    checkBox.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            try {
              method.invoke(instance, isChecked);
            } catch (Exception e) {
              Log.e("Bee", e.getMessage());
            }

            PrefHelper.setBoolean(context, method.getName(), isChecked);
          }
        });
    checkBox.setChecked(PrefHelper.getBoolean(context, method.getName()));

    return view;
  }
예제 #2
0
  private View createButton(ViewGroup parent, MethodInfo methodInfo) {

    final Method method = methodInfo.getMethod();
    final Object instance = methodInfo.getInstance();

    View view = inflater.inflate(R.layout.item_settings_button, parent, false);
    Button button = (Button) view.findViewById(R.id.button);
    button.setText(methodInfo.getTitle());
    button.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            try {
              method.invoke(instance);
            } catch (Exception e) {
              Log.e("Bee", e.getMessage());
            }
          }
        });

    return view;
  }
예제 #3
0
  private View createSpinner(ViewGroup parent, MethodInfo methodInfo) {

    final Method method = methodInfo.getMethod();
    final Object instance = methodInfo.getInstance();
    final Context context = parent.getContext();

    View view = inflater.inflate(R.layout.item_settings_spinner, parent, false);
    ((TextView) view.findViewById(R.id.title)).setText(methodInfo.getTitle());

    String[] dataList = (String[]) methodInfo.getData();
    ArrayAdapter<String> adapter =
        new ArrayAdapter<>(parent.getContext(), R.layout.simple_spinner_item, dataList);

    Spinner spinner = (Spinner) view.findViewById(R.id.spinner);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String value = (String) parent.getItemAtPosition(position);

            try {
              method.invoke(instance, value);
            } catch (Exception e) {
              Log.e("Bee", e.getMessage());
            }

            PrefHelper.setInt(context, method.getName(), position);
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });
    spinner.setSelection(PrefHelper.getInt(context, method.getName()));
    return view;
  }