Example usage for android.widget ToggleButton isChecked

List of usage examples for android.widget ToggleButton isChecked

Introduction

In this page you can find the example usage for android.widget ToggleButton isChecked.

Prototype

@ViewDebug.ExportedProperty
    @Override
    public boolean isChecked() 

Source Link

Usage

From source file:com.emorym.android_pusher.DeprecatedPusherSampleActivity.java

/** Called when the activity is first created. */
@Override/*from   www .  j a  v a  2 s. com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.main);

    // This Handler is going to deal with incoming messages
    mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Bundle bundleData = msg.getData();
            if (bundleData.getString("type").contentEquals("pusher")) {
                try {
                    JSONObject message = new JSONObject(bundleData.getString("message"));

                    Log.d("Pusher Message", message.toString());

                    Toast.makeText(mContext, message.toString(), Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    };

    mPusher = new Pusher(mHandler);
    mPusher.connect(PUSHER_APP_KEY);

    // Setup some toggles to subscribe/unsubscribe from our 2 test channels
    final ToggleButton test1 = (ToggleButton) findViewById(R.id.toggleButton1);
    final ToggleButton test2 = (ToggleButton) findViewById(R.id.toggleButton2);

    final Button send = (Button) findViewById(R.id.send_button);

    test1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (test1.isChecked())
                mPusher.subscribe(PUSHER_CHANNEL_1);
            else
                mPusher.unsubscribe(PUSHER_CHANNEL_1);
        }
    });

    test2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (test2.isChecked())
                mPusher.subscribe(PUSHER_CHANNEL_2);
            else
                mPusher.unsubscribe(PUSHER_CHANNEL_2);
        }
    });

    send.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EditText channelName = (EditText) findViewById(R.id.channel_name);
            EditText eventName = (EditText) findViewById(R.id.event_name);
            EditText eventData = (EditText) findViewById(R.id.event_data);

            try {
                JSONObject data = new JSONObject();
                data.put("data", eventData.getText().toString());
                mPusher.send(eventName.getText().toString(), data, channelName.getText().toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:com.emorym.android_pusher.PusherSampleActivity.java

/** Called when the activity is first created. */
@Override//from   ww w .  jav a 2 s . co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.main);

    // This Handler is going to deal with incoming messages
    mPusher = new Pusher(PUSHER_APP_KEY);
    mPusher.bindAll(new PusherCallback() {
        @Override
        public void onEvent(String eventName, JSONObject eventData) {
            Log.d("Pusher Message", "Any Channel: " + eventName + " - " + eventData.toString());
        }
    });

    // Setup some toggles to subscribe/unsubscribe from our 2 test channels
    final ToggleButton test1 = (ToggleButton) findViewById(R.id.toggleButton1);
    final ToggleButton test2 = (ToggleButton) findViewById(R.id.toggleButton2);

    final Button send = (Button) findViewById(R.id.send_button);

    test1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (test1.isChecked()) {
                Channel channel1 = mPusher.subscribe(PUSHER_CHANNEL_1);
                channel1.bind("message:received", new PusherCallback() {
                    @Override
                    public void onEvent(JSONObject eventData) {
                        Log.d("Pusher Message", PUSHER_CHANNEL_1 + ":" + eventData.toString());
                        Toast.makeText(mContext, eventData.toString(), Toast.LENGTH_SHORT).show();
                    }
                });
            } else {
                mPusher.unsubscribe(PUSHER_CHANNEL_1);
            }
        }
    });

    test2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (test2.isChecked()) {
                Channel channel2 = mPusher.subscribe(PUSHER_CHANNEL_2);
                channel2.bindAll(new PusherCallback() {
                    @Override
                    public void onEvent(String eventName, JSONObject eventData) {
                        Log.d("Pusher Message",
                                PUSHER_CHANNEL_2 + ":" + eventName + " " + eventData.toString());
                        EditText eventDataField = (EditText) findViewById(R.id.event_data);
                        eventDataField.setText(eventData.toString());
                    }
                });
            } else {
                mPusher.unsubscribe(PUSHER_CHANNEL_2);
            }
        }
    });

    send.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EditText channelName = (EditText) findViewById(R.id.channel_name);
            EditText eventName = (EditText) findViewById(R.id.event_name);
            EditText eventData = (EditText) findViewById(R.id.event_data);

            try {
                JSONObject data = new JSONObject();
                data.put("data", eventData.getText().toString());
                mPusher.send(eventName.getText().toString(), data, channelName.getText().toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:com.coinprism.wallet.fragment.BalanceTab.java

/**
 * Constructs the UI when the activity is first rendered.
 *
 * @param rootView the rootView of the fragment
 *///from  w  w  w.  j a va2  s . c o  m
public void setupUI(final View rootView) {
    final WalletState state = WalletState.getState();

    final TextView addressText = (TextView) rootView.findViewById(R.id.address);
    final ImageView qrCode = (ImageView) rootView.findViewById(R.id.qrAddress);

    final ToggleButton addressTypeSelector = (ToggleButton) rootView.findViewById(R.id.addressTypeSelector);

    final View.OnClickListener enlarge = new View.OnClickListener() {
        // Enlarge the QR code
        @Override
        public void onClick(View view) {
            final QRCodeDialog dialog = new QRCodeDialog();
            if (addressTypeSelector.isChecked()) {
                dialog.configure(WalletState.getState().getConfiguration().getReceiveAssetAddress(),
                        getString(R.string.tab_wallet_dialog_qr_title_assets));
            } else {
                dialog.configure(WalletState.getState().getConfiguration().getAddress(),
                        getString(R.string.tab_wallet_dialog_qr_title_bitcoin));
            }

            dialog.show(BalanceTab.this.getActivity().getSupportFragmentManager(), "");
        }
    };

    LinearLayout addressPanel = (LinearLayout) rootView.findViewById(R.id.addressArea);
    addressPanel.setOnClickListener(enlarge);
    qrCode.setOnClickListener(enlarge);

    addressTypeSelector.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (addressTypeSelector.isChecked()) {
                addressText.setText(state.getConfiguration().getReceiveAssetAddress());
                QRCodeEncoder.createQRCode(state.getConfiguration().getReceiveAssetAddress(), qrCode, 148, 148,
                        8, 0xFFFFFFFF);
            } else {
                addressText.setText(state.getConfiguration().getAddress());
                QRCodeEncoder.createQRCode(state.getConfiguration().getAddress(), qrCode, 148, 148, 8,
                        0xFFFFFFFF);
            }
        }
    });

    addressTypeSelector.setChecked(true);
}

From source file:com.lightstreamer.demo.android.DetailsFragment.java

public void togglePN(ToggleButton toggle) {
    //TODO toggle status can be overridden by the onMpnStatusChanged: find a user friendly way to handle the case
    boolean on = toggle.isChecked();
    if (currentItem != 0) {
        if (on) {
            Log.v(TAG, "PN enabled for item" + currentItem);
            this.subscriptionHandling.activateMPN(getMpnInfo(-1));
        } else {//from   w ww.j a  v a2 s .c  o  m
            Log.v(TAG, "PN disabled for item" + currentItem);
            this.subscriptionHandling.deactivateMPN(getMpnInfo(-1));
        }

    }
}

From source file:com.google.android.car.kitchensink.camera.CameraTestFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
    View v = inflater.inflate(R.layout.camera_test, container, false);

    int[] cameraList = mCarCameraManager.getCameraList();
    for (int camera : cameraList) {
        if (camera == CarCameraManager.CAR_CAMERA_TYPE_RVC) {
            mRvcCamera = mCarCameraManager.openCamera(1);
            break;
        }/*from  ww  w .jav a2  s  .  c om*/
    }

    mTvCap = (TextView) v.findViewById(R.id.tvCap);
    mTvRvcCrop = (TextView) v.findViewById(R.id.tvRvcCrop);
    mTvRvcPos = (TextView) v.findViewById(R.id.tvRvcPos);
    mTvCameraState = (TextView) v.findViewById(R.id.tvCameraState);

    Button btn = (Button) v.findViewById(R.id.btnGetCap);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                int cap = mRvcCamera.getCapabilities();
                mTvCap.setText(String.valueOf(cap));
            } catch (CarNotConnectedException e) {
                Log.e(TAG, "Failed to get camera capabilities", e);
            }
        }
    });

    btn = (Button) v.findViewById(R.id.btnGetRvcCrop);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                Rect rect = mRvcCamera.getCameraCrop();
                if (rect != null) {
                    mTvRvcCrop.setText(rect.toString());
                } else {
                    mTvRvcCrop.setText("null");
                }
            } catch (CarNotConnectedException e) {
                Log.e(TAG, "Failed to get camera crop", e);
            }
        }
    });

    btn = (Button) v.findViewById(R.id.btnGetRvcPos);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                Rect rect = mRvcCamera.getCameraPosition();
                if (rect != null) {
                    mTvRvcPos.setText(String.valueOf(rect));
                } else {
                    mTvRvcPos.setText("null");
                }
            } catch (CarNotConnectedException e) {
                Log.e(TAG, "Failed to get camere position", e);
            }
        }
    });

    btn = (Button) v.findViewById(R.id.btnGetCameraState);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                CarCameraState state = mRvcCamera.getCameraState();
                if (state != null) {
                    mTvCameraState.setText(state.toString());
                } else {
                    mTvCameraState.setText("null");
                }
            } catch (CarNotConnectedException e) {
                Log.e(TAG, "Failed to get camere state", e);
            }
        }
    });

    btn = (Button) v.findViewById(R.id.btnSetRvcCrop);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Rect rect = new Rect(160, 240, 560, 480);
            try {
                mRvcCamera.setCameraCrop(rect);
            } catch (CarNotConnectedException e) {
                Log.e(TAG, "Failed to set camera crop", e);
            }
        }
    });

    btn = (Button) v.findViewById(R.id.btnSetRvcCrop2);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Rect rect = new Rect(0, 0, 720, 480);
            try {
                mRvcCamera.setCameraCrop(rect);
            } catch (CarNotConnectedException e) {
                Log.e(TAG, "Failed to set camera crop", e);
            }
        }
    });

    btn = (Button) v.findViewById(R.id.btnSetRvcPos);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Rect rect = new Rect(300, 0, 800, 480);
            try {
                mRvcCamera.setCameraPosition(rect);
            } catch (CarNotConnectedException e) {
                Log.e(TAG, "Failed to set camera position", e);
            }
        }
    });

    btn = (Button) v.findViewById(R.id.btnSetRvcPos2);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Rect rect = new Rect(500, 0, 800, 480);
            try {
                mRvcCamera.setCameraPosition(rect);
            } catch (CarNotConnectedException e) {
                Log.e(TAG, "Failed to set camera position", e);
            }
        }
    });

    btn = (Button) v.findViewById(R.id.btnSetRvcPos3);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Rect rect = new Rect(300, 0, 500, 300);
            try {
                mRvcCamera.setCameraPosition(rect);
            } catch (CarNotConnectedException e) {
                Log.e(TAG, "Failed to set camera position", e);
            }
        }
    });

    final ToggleButton toggleBtn = (ToggleButton) v.findViewById(R.id.btnRvcState);
    toggleBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            CarCameraState state = new CarCameraState(false, toggleBtn.isChecked());
            try {
                mRvcCamera.setCameraState(state);
            } catch (CarNotConnectedException e) {
                Log.e(TAG, "Failed to set camera state", e);
            }
        }
    });

    if (DBG) {
        Log.d(TAG, "Starting CameraTestFragment");
    }
    return v;
}

From source file:com.quaap.audiometer.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    pref = getApplicationContext().getSharedPreferences("main", MODE_PRIVATE);
    mMeterView = (MeterView) findViewById(R.id.meterLayout);

    mMicLevelReader = new MicLevelReader(this, LevelMethod.dBFS);

    ImageButton show_ctrls = (ImageButton) findViewById(R.id.show_ctrls);
    show_ctrls.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w w  w . ja  v a  2 s .c  o m*/
        public void onClick(View view) {
            ViewSwitcher ctrls = (ViewSwitcher) findViewById(R.id.ctrls);
            ctrls.showNext();
        }
    });
    ImageButton hide_ctrls = (ImageButton) findViewById(R.id.hide_ctrls);
    hide_ctrls.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ViewSwitcher ctrls = (ViewSwitcher) findViewById(R.id.ctrls);
            ctrls.showPrevious();
        }
    });

    final SeekBar scaleCtrl = (SeekBar) findViewById(R.id.scaleCtrl);

    scaleCtrl.setProgress(pref.getInt("scaleCtrl", scaleCtrl.getProgress()));

    setScale();

    scaleCtrl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            setScale();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

    final ToggleButton onoff = (ToggleButton) findViewById(R.id.toggleButton);

    onoff.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (onoff.isChecked()) {
                if (!startit()) {
                    onoff.setChecked(false);
                }
            } else {
                stopit();
            }
        }
    });

    LevelMethod levM = LevelMethod.valueOf(pref.getString("levelMethod", LevelMethod.dBFS.toString()));

    final Spinner levelType = (Spinner) findViewById(R.id.levelType);
    ArrayAdapter<LevelMethod> levelTypeAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_spinner_dropdown_item, LevelMethod.values());
    levelType.setAdapter(levelTypeAdapter);

    levelType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            LevelMethod lmeth = (LevelMethod) adapterView.getSelectedItem();
            levelMethodChanged(lmeth);

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    levelType.setSelection(levelTypeAdapter.getPosition(levM));

    levelMethodChanged((LevelMethod) levelType.getSelectedItem());
    checkMicrophoneAccess();
}

From source file:com.msdpe.storagedemo.ContainersActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        ////from  w ww . j  ava  2s . co m
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        NavUtils.navigateUpFromSameTask(this);
        return true;
    case R.id.action_add_container:
        //Show new container dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        // Get the layout inflater
        LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
        //Create our dialog view
        View dialogView = inflater.inflate(R.layout.dialog_new_container, null);
        final EditText txtContainerName = (EditText) dialogView.findViewById(R.id.txtContainerName);
        final ToggleButton btnIsPublic = (ToggleButton) dialogView.findViewById(R.id.btnIsPublic);
        builder.setView(dialogView).setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                //When they click OK, add the container
                mStorageService.addContainer(txtContainerName.getText().toString(), btnIsPublic.isChecked());
            }
        }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        //Show the dialog
        builder.show();
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.google.android.apps.watchme.StreamerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.d(MainActivity.APP_NAME, "onCreate");
    super.onCreate(savedInstanceState);

    broadcastId = getIntent().getStringExtra(YouTubeApi.BROADCAST_ID_KEY);
    //Log.v(MainActivity.APP_NAME, broadcastId);

    rtmpUrl = getIntent().getStringExtra(YouTubeApi.RTMP_URL_KEY);

    if (rtmpUrl == null) {
        Log.w(MainActivity.APP_NAME, "No RTMP URL was passed in; bailing.");
        finish();//from w w  w .  j a  va  2s .c  om
    }
    Log.i(MainActivity.APP_NAME, String.format("Got RTMP URL '%s' from calling activity.", rtmpUrl));

    setContentView(R.layout.streamer);
    // @edsonAndrade
    //Setting the textview as the main video display for camera2 api
    textureView = (TextureView) findViewById(R.id.surfaceViewPreview);
    //preview = (Preview) findViewById(R.id.surfaceViewPreview);

    if (!bindService(new Intent(this, StreamerService.class), streamerConnection,
            BIND_AUTO_CREATE | BIND_DEBUG_UNBIND)) {
        Log.e(MainActivity.APP_NAME, "Failed to bind StreamerService!");
    }

    recordImageButtton = (ImageButton) findViewById(R.id.toggleBroadcasting);
    recordImageButtton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isRecording) {
                isRecording = false;
                //recordImageButtton.setImageResource(R.mipmap.);
            }
        }
    });

    final ToggleButton switchCamera = (ToggleButton) findViewById(R.id.button);
    switchCamera.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (switchCamera.isChecked()) {
                //                    streamerService.startStreaming(rtmpUrl);
            } else {
                //                    streamerService.stopStreaming();
            }
        }
    });
}

From source file:de.uni_weimar.mheinz.androidtouchscope.TouchScopeActivity.java

public void onAuto(View view) {
    mLearningView.doAnim(LearningView.Controls.AUTO_BUTTON);

    final ToggleButton button = (ToggleButton) view;
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override//  www  . j  av a  2  s .c  o m
        public void run() {
            if (mActiveScope != null)
                mActiveScope.doCommand(ScopeInterface.Command.DO_AUTO, 0, true, button.isChecked());

            Log.i(TAG, "Auto Completed");
            button.setChecked(false);
        }
    }, 0);

    mCursorStruct.cursorMode = CursorStruct.CursorMode.OFF;
    setCursorModeState(CursorStruct.CursorMode.OFF);
    mScopeView.setCursorsState(mCursorStruct);
}

From source file:com.towson.wavyleaf.Sighting.java

public String getSelectedToggleButton() {
    String str = "";
    for (int i = 0; i < rg.getChildCount(); i++) {
        View child = rg.getChildAt(i);
        if (child instanceof LinearLayout) {
            for (int j = 0; j < ((ViewGroup) child).getChildCount(); j++) {
                final ToggleButton tog = (ToggleButton) ((ViewGroup) child).getChildAt(j);
                if (tog.isChecked())
                    str = tog.getText().toString();
            }/* ww  w. j a v a  2  s  . c om*/
        }
    }
    return str;
}