private void setWifiStatus(boolean onOff) {
    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    if (onOff) {
      if (wifi.isWifiEnabled() == false) {
        Toast.makeText(
                getApplicationContext(),
                "Wifi is disabled. It is being enabled.",
                Toast.LENGTH_LONG)
            .show();
      }
      wifi.setWifiEnabled(true);
      scanning_textView.setVisibility(View.GONE);
      wifiListview.setVisibility(View.VISIBLE);
      wifiOnOff.setChecked(true);
      wifiOnOff.setBackgroundColor(getResources().getColor(R.color.greenEnd));
    } else {

      Toast.makeText(getApplicationContext(), "Wifi is disabled.", Toast.LENGTH_LONG).show();
      wifi.setWifiEnabled(false);
      wifiOnOff.setChecked(false);
      wifiOnOff.setBackgroundColor(getResources().getColor(R.color.lightGrey));
      scanning_textView.setVisibility(View.GONE);
      wifiListview.setVisibility(View.GONE);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(LAYOUT);

    sensorData = new SensorData();
    //        sensorData = (SensorData) Serialization.deserExternalData(Serialization.DATA_FILE);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    scanToggleButton = (ToggleButton) findViewById(R.id.scan_toggle_button);
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    scanToggleButton.setBackgroundColor(Color.parseColor("#259C25"));
    scanToggleButton.setOnCheckedChangeListener(this);
    restartButton = (Button) findViewById(R.id.restart_button);
    restartButton.setOnClickListener(this);
  }
Example #3
0
  /** Category 선택 위해 Dialog띄우는 메소드 */
  private void displayCategoryDialog() {
    refreshHandler.removeCallbacks(refreshRunnable); // 새로고침 중단

    LayoutInflater inflater = getLayoutInflater();
    final View dialogView = inflater.inflate(R.layout.dialog_category, null);

    AlertDialog.Builder builder =
        new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));
    builder.setView(dialogView);
    builder.setTitle("카테고리 선택");

    final ToggleButton dialogBtn = (ToggleButton) dialogView.findViewById(R.id.dialog_toggle);
    final GridView gridView = (GridView) dialogView.findViewById(R.id.dialog_gridview);
    final CategoryAdapter categoryAdapter =
        new CategoryAdapter(
            this, R.layout.grid_category_item, R.id.category_txt, CategoryAdapter.items);
    gridView.setAdapter(categoryAdapter);

    dialogBtn.setChecked(CategoryAdapter.total);
    if (dialogBtn.isChecked())
      dialogBtn.setBackgroundColor(getResources().getColor(R.color.Orange));
    else dialogBtn.setBackgroundColor(getResources().getColor(R.color.lightlightOrange));

    dialogBtn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (dialogBtn.isChecked()) {
              dialogBtn.setBackgroundColor(getResources().getColor(R.color.Orange));
              CategoryAdapter.total = true;
              for (int i = 0; i < CategoryAdapter.selectedItemsIds.size(); i++) {
                CategoryAdapter.selectedItemsIds.put(i, false);
                categoryAdapter.getView(i).setAlpha(0.5f);
              }
              categoryAdapter.notifyDataSetChanged();
            } else {
              dialogBtn.setBackgroundColor(getResources().getColor(R.color.lightlightOrange));
              CategoryAdapter.total = false;
            }
          }
        });

    gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
    gridView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            categoryAdapter.toggleSelection(position, view);
            // Category 선택하면 "전체" 선택 해제
            CategoryAdapter.total = false;
            dialogBtn.setChecked(CategoryAdapter.total);
            dialogBtn.setBackgroundColor(getResources().getColor(R.color.lightlightOrange));
          }
        });

    DialogInterface.OnClickListener listener =
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
              // 아무것도 선택되지 않았을 경우 '전체'로 셋팅
              boolean none = true;
              for (int i = 0; i < categoryAdapter.selectedItemsIds.size(); i++) {
                if (categoryAdapter.selectedItemsIds.get(i)) none = false;
              }
              if (none) CategoryAdapter.total = true;

              // 버튼 텍스트 셋팅
              String str = "";
              if (CategoryAdapter.total) {
                str = "전체";
              } else {
                for (int i = 0; i < categoryAdapter.selectedItemsIds.size(); i++) {
                  if (categoryAdapter.selectedItemsIds.get(i)) {
                    str += CategoryAdapter.items[i] + " ";
                  }
                }
              }
              saveSPrf();
              categoryButton.setText(str);
            } else if (which == DialogInterface.BUTTON_NEUTRAL) {
              loadSPrf(); // 기존 저장된 값으로 롤백
              dialog.dismiss();
            }
            refreshRunnable.run(); // 새로고침 시작
          }
        };
    builder.setPositiveButton("선택", listener);
    builder.setNeutralButton("취소", listener);
    builder.setCancelable(true);
    AlertDialog dialog = builder.show();

    // Dialog 색깔 바꾸기
    int titleDividerId = getResources().getIdentifier("titleDivider", "id", "android");
    View titleDivider = dialog.findViewById(titleDividerId);
    if (titleDivider != null)
      titleDivider.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
  }