Java Code Examples for android.widget.ToggleButton#setOnCheckedChangeListener()

The following examples show how to use android.widget.ToggleButton#setOnCheckedChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkListenerTestActivity.java    From android-utilset with Apache License 2.0 6 votes vote down vote up
@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_network_listener);

		networkUtils = NetworkMonitor.getInstance(this);
		
		wifiStateTextView = (TextView) findViewById(R.id.network_listener_test_wifi_state);
		networkStateTextView = (TextView) findViewById(R.id.network_listener_test_network_state);
//		unusedTextView = (TextView) findViewById(R.id.network_listener_test_unused);

		toggleWifiButton = (ToggleButton) findViewById(R.id.network_listener_test_toggle_wifi);
		toggleWifiButton.setOnCheckedChangeListener(onCheckedChangeListener);
		
		init();
	}
 
Example 2
Source File: MainActivity.java    From android-flat-button with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    twitterBtn = (FButton) findViewById(R.id.f_twitter_button);
    disabledBtn = (FButton) findViewById(R.id.disabled_button);
    Button changeColorBtn = (Button) findViewById(R.id.change_color_button);
    ToggleButton shadowSwitch = (ToggleButton) findViewById(R.id.enable_shadow_switch);
    shadowHeightBar = (SeekBar) findViewById(R.id.shadow_height_seekbar);
    shadowHeight = (TextView) findViewById(R.id.shadow_height_value);

    changeColorBtn.setOnClickListener(this);
    shadowSwitch.setOnCheckedChangeListener(this);
    shadowHeightBar.setOnSeekBarChangeListener(this);

    //Config disabled button
    disabledBtn.setButtonColor(getResources().getColor(R.color.fbutton_color_concrete));
    disabledBtn.setShadowEnabled(true);
    disabledBtn.setShadowHeight(5);
    disabledBtn.setCornerRadius(5);
}
 
Example 3
Source File: AccelerometerManager.java    From SensorAnnotations with Apache License 2.0 6 votes vote down vote up
AccelerometerManager(@NonNull MainActivity mainActivity) {
    mMainActivity = mainActivity;

    mAccelerometerManagerTextView =
        (TextView) mMainActivity.findViewById(R.id.accelerometer_event_output);

    ToggleButton accelerometerButton =
        (ToggleButton) mMainActivity.findViewById(R.id.accelerometer_button);

    accelerometerButton.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    // Example of binding to another object, a Context is still needed:
                    SensorAnnotations.bind(AccelerometerManager.this, buttonView.getContext());
                } else {
                    SensorAnnotations.unbind(AccelerometerManager.this);
                    mMainActivity.updateTextViewWithSensorNotBound(
                        mAccelerometerManagerTextView);
                }
            }
        });
}
 
Example 4
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	verifyPlayServices();

	mLocationClient = new LocationClient( this, this, this );
	mIntent = new Intent( this, GeofencingService.class );
	mPendingIntent = PendingIntent.getService( this, 0, mIntent, PendingIntent.FLAG_UPDATE_CURRENT );

	mToggleButton = (ToggleButton) findViewById( R.id.geofencing_button );
	mToggleButton.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged( CompoundButton compoundButton, boolean b ) {
			if( b ) {
				startGeofence();
			} else {
				stopGeofence();
			}
		}
	});
}
 
Example 5
Source File: HintFragment.java    From android-crackme-challenge with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_hint, container, false);
    final ToggleButton switchShowHint = (ToggleButton) view.findViewById(R.id.switch_show_hint);
    switchShowHint.setOnCheckedChangeListener(new HintFragmentOnCheckedChangeListener((TextView) view.findViewById(R.id.text_hint)));
    return view;
}
 
Example 6
Source File: DebugFragment.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    registerEventBus();

    v = inflater.inflate(R.layout.debug_fragment, container, false);

    mListView = v.findViewById(R.id.logwrapper);

    mArrayAdapter = new MyAdapter();
    mListView.setAdapter(mArrayAdapter);
    mListView.setItemAnimator(null);
    mListView.setOnTouchListener((v, event) -> false);

    ToggleButton toggleLock = v.findViewById(R.id.toogleLockList);
    toggleLock.setOnCheckedChangeListener((buttonView, isChecked) -> isLockPosition = isChecked);

    Button close = v.findViewById(R.id.close);
    close.setOnClickListener(v -> getActivity().getSupportFragmentManager().beginTransaction().remove(DebugFragment.this).commit());

    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setStackFromEnd(true);

    mListView.setLayoutManager(mLayoutManager);

    return v;
}
 
Example 7
Source File: HintFragment.java    From android-crackme-challenge with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_hint, container, false);
    final ToggleButton switchShowHint = (ToggleButton) view.findViewById(R.id.switch_show_hint);
    switchShowHint.setOnCheckedChangeListener(new HintFragmentOnCheckedChangeListener((TextView) view.findViewById(R.id.text_hint)));
    return view;
}
 
Example 8
Source File: HintFragment.java    From android-crackme-challenge with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_hint, container, false);
    final ToggleButton switchShowHint = (ToggleButton) view.findViewById(R.id.switch_show_hint);
    switchShowHint.setOnCheckedChangeListener(new HintFragmentOnCheckedChangeListener((TextView) view.findViewById(R.id.text_hint)));
    return view;
}
 
Example 9
Source File: HintFragment.java    From android-crackme-challenge with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_hint, container, false);
    final ToggleButton switchShowHint = (ToggleButton) view.findViewById(R.id.switch_show_hint);
    switchShowHint.setOnCheckedChangeListener(new HintFragmentOnCheckedChangeListener((TextView) view.findViewById(R.id.text_hint)));
    return view;
}
 
Example 10
Source File: SettingActivity.java    From EverMemo with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	overridePendingTransition(R.anim.in_push_right_to_left,
			R.anim.in_stable);
	mContext = this;
	mSharedPreferences = PreferenceManager
			.getDefaultSharedPreferences(mContext);
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activtiy_setting);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setDisplayShowHomeEnabled(false);
	getSupportActionBar().setDisplayShowTitleEnabled(true);
	getSupportActionBar().setTitle(getString(R.string.setting));
	getSupportActionBar().setDisplayUseLogoEnabled(false);
	mBindEvernote = (ViewGroup) findViewById(R.id.bind_evernote);
	mBindText = (TextView) findViewById(R.id.bind_text);
	mToggleButton = (ToggleButton) findViewById(R.id.open_toggle);
	mBindEvernote.setOnClickListener(this);
	mEvernote = new Evernote(mContext, this);
	if (mEvernote.isLogin()) {
		bindSuccess();
	}
	mToggleButton.setOnCheckedChangeListener(this);
	mToggleButton.setChecked(mSharedPreferences.getBoolean(
			OPEN_MEMO_WHEN_START_UP, false));
	findViewById(R.id.rate).setOnClickListener(this);
	findViewById(R.id.setting_start).setOnClickListener(this);
}
 
Example 11
Source File: SettingActivity.java    From AnimeTaste with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	mContext = this;
	ShareSDK.initSDK(mContext);
	setContentView(R.layout.activity_setting);
	getSupportActionBar().setDisplayShowTitleEnabled(false);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	mRecommand = findViewById(R.id.recommend);
	mSuggestion = findViewById(R.id.suggestion);
	mFocusUs = findViewById(R.id.focus_us);
	mCancelAuth = findViewById(R.id.cancel_auth);
	mRateForUs = findViewById(R.id.rate_for_us);
       mClearCache = findViewById(R.id.clear_cache);

	mSwitchOnlyWifi = (ToggleButton) findViewById(R.id.switch_wifi);
	mSwitchUseHD = (ToggleButton) findViewById(R.id.switch_hd);

	mSharedPreferences = PreferenceManager
			.getDefaultSharedPreferences(this);

	mRecommand.setOnClickListener(this);
	mSuggestion.setOnClickListener(this);
	mFocusUs.setOnClickListener(this);
	mSwitchOnlyWifi.setOnCheckedChangeListener(this);
	mSwitchUseHD.setOnCheckedChangeListener(this);
	mCancelAuth.setOnClickListener(this);
	mRateForUs.setOnClickListener(this);
       mClearCache.setOnClickListener(this);

	mSwitchOnlyWifi.setChecked(mSharedPreferences.getBoolean("only_wifi",
			true));
	mSwitchUseHD.setChecked(mSharedPreferences.getBoolean("use_hd", true));
}
 
Example 12
Source File: HintFragment.java    From android-crackme-challenge with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_hint, container, false);
    final ToggleButton switchShowHint = (ToggleButton) view.findViewById(R.id.switch_show_hint);
    switchShowHint.setOnCheckedChangeListener(new HintFragmentOnCheckedChangeListener((TextView) view.findViewById(R.id.text_hint)));
    return view;
}
 
Example 13
Source File: ConfigureTimerDialogPage2DaysFragment.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.dialog_fragment_configure_timer_page_2, container, false);

    CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            sendTimerEexecutionIntervalChangedBroadcast(getContext(), 1000, getSelectedDays(), Timer
                    .EXECUTION_TYPE_WEEKDAY);
        }
    };

    toggleButtonMonday = (ToggleButton) rootView.findViewById(R.id.toggleButton_monday);
    toggleButtonMonday.setOnCheckedChangeListener(onCheckedChangeListener);
    toggleButtonTuesday = (ToggleButton) rootView.findViewById(R.id.toggleButton_tuesday);
    toggleButtonTuesday.setOnCheckedChangeListener(onCheckedChangeListener);
    toggleButtonWednesday = (ToggleButton) rootView.findViewById(R.id.toggleButton_wednesday);
    toggleButtonWednesday.setOnCheckedChangeListener(onCheckedChangeListener);
    toggleButtonThursday = (ToggleButton) rootView.findViewById(R.id.toggleButton_thursday);
    toggleButtonThursday.setOnCheckedChangeListener(onCheckedChangeListener);
    toggleButtonFriday = (ToggleButton) rootView.findViewById(R.id.toggleButton_friday);
    toggleButtonFriday.setOnCheckedChangeListener(onCheckedChangeListener);
    toggleButtonSaturday = (ToggleButton) rootView.findViewById(R.id.toggleButton_saturday);
    toggleButtonSaturday.setOnCheckedChangeListener(onCheckedChangeListener);
    toggleButtonSunday = (ToggleButton) rootView.findViewById(R.id.toggleButton_sunday);
    toggleButtonSunday.setOnCheckedChangeListener(onCheckedChangeListener);

    Bundle args = getArguments();
    if (args != null && args.containsKey(ConfigureTimerDialog.TIMER_ID_KEY)) {
        long timerId = args.getLong(ConfigureTimerDialog.TIMER_ID_KEY);
        initializeTimerData(timerId);
    }

    return rootView;
}
 
Example 14
Source File: MeUltrasonic.java    From Makeblock-App-For-Android with MIT License 4 votes vote down vote up
public void setDisable(){
	toggleBt = (ToggleButton)view.findViewById(R.id.autoSwitch);
	toggleBt.setOnCheckedChangeListener(null);
}
 
Example 15
Source File: ContentsBaseFragment.java    From android-openslmediaplayer with Apache License 2.0 4 votes vote down vote up
protected ToggleButton findToggleButtonByIdAndSetListener(int id) {
    ToggleButton toggleButtton = findToggleButtonById(id);
    toggleButtton.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener) this);
    return toggleButtton;
}
 
Example 16
Source File: Recognize.java    From marvel with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recognize);

    scan = (ToggleButton) findViewById(R.id.scan);
    final TextView results = (TextView) findViewById(R.id.results);

    mOpenCvCameraView = (Tutorial3View) findViewById(R.id.tutorial3_activity_java_surface_view);
    mOpenCvCameraView.setCvCameraViewListener(this);

    //mPath=getFilesDir()+"/facerecogOCV/";
    mPath = Environment.getExternalStorageDirectory()+"/facerecogOCV/";

    Log.e("Path", mPath);

    labelsFile= new Labels(mPath);

    mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            /*
                display a newline separated list of individual names
             */
            String tempName = msg.obj.toString();
            if (!(tempName.equals("Unknown"))) {
                tempName = capitalize(tempName);
                uniqueNames.add(tempName);
                uniqueNamesArray = uniqueNames.toArray(new String[uniqueNames.size()]);
                StringBuilder strBuilder = new StringBuilder();
                for (int i = 0; i < uniqueNamesArray.length; i++) {
                    strBuilder.append(uniqueNamesArray[i] + "\n");
                }
                String textToDisplay = strBuilder.toString();
                results.setText(textToDisplay);
            }
        }
    };

    scan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if(b) {
                if(!fr.canPredict()) {
                    scan.setChecked(false);
                    Toast.makeText(getApplicationContext(), getResources().getString(R.string.SCanntoPredic), Toast.LENGTH_LONG).show();
                    return;
                }
                faceState = SEARCHING;
            }
            else {
                faceState = IDLE;
            }
        }
    });

    boolean success=(new File(mPath)).mkdirs();
    if (!success)
    {
        Log.e("Error","Error creating directory");
    }

    Button submit = (Button) findViewById(R.id.submit);
    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(uniqueNames.size() > 0) {
                Intent intent = new Intent(Recognize.this, ReviewResults.class);
                intent.putExtra("list", uniqueNamesArray);
                startActivity(intent);
            }
            else {
                Toast.makeText(Recognize.this, "Empty list cannot be sent further", Toast.LENGTH_LONG).show();
            }
        }
    });

}
 
Example 17
Source File: BottomAppBarMainDemoFragment.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View view = layoutInflater.inflate(getBottomAppBarContent(), viewGroup, false);

  Toolbar toolbar = view.findViewById(R.id.toolbar);
  toolbar.setTitle(getDefaultDemoTitle());
  themeSwitcherHelper.onCreateOptionsMenu(toolbar.getMenu(), getActivity().getMenuInflater());
  toolbar.setOnMenuItemClickListener(themeSwitcherHelper::onOptionsItemSelected);
  toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());

  coordinatorLayout = view.findViewById(R.id.coordinator_layout);
  bar = view.findViewById(R.id.bar);
  ((AppCompatActivity) getActivity()).setSupportActionBar(bar);

  setUpBottomDrawer(view);

  fab = view.findViewById(R.id.fab);
  fab.setOnClickListener(v -> showSnackbar(fab.getContentDescription()));
  NavigationView navigationView = view.findViewById(R.id.navigation_view);
  navigationView.setNavigationItemSelectedListener(
      item -> {
        showSnackbar(item.getTitle());
        return false;
      });

  Button centerButton = view.findViewById(R.id.center);
  Button endButton = view.findViewById(R.id.end);
  ToggleButton attachToggle = view.findViewById(R.id.attach_toggle);
  attachToggle.setChecked(fab.getVisibility() == View.VISIBLE);
  centerButton.setOnClickListener(
      v -> {
        bar.setFabAlignmentModeAndReplaceMenu(
            BottomAppBar.FAB_ALIGNMENT_MODE_CENTER, R.menu.demo_primary);
      });
  endButton.setOnClickListener(
      v -> {
        bar.setFabAlignmentModeAndReplaceMenu(
            BottomAppBar.FAB_ALIGNMENT_MODE_END, R.menu.demo_primary_alternate);
      });
  attachToggle.setOnCheckedChangeListener(
      (buttonView, isChecked) -> {
        if (isChecked) {
          fab.show();
        } else {
          fab.hide();
        }
      });

  ToggleButton barScrollToggle = view.findViewById(R.id.bar_scroll_toggle);
  barScrollToggle.setChecked(bar.getHideOnScroll());
  barScrollToggle.setOnCheckedChangeListener(
      (buttonView, isChecked) -> bar.setHideOnScroll(isChecked));

  ToggleButton fabAnimToggle = view.findViewById(R.id.fab_animation_mode_toggle);
  fabAnimToggle.setOnCheckedChangeListener(
      (buttonView, isChecked) ->
          bar.setFabAnimationMode(
              isChecked
                  ? BottomAppBar.FAB_ANIMATION_MODE_SLIDE
                  : BottomAppBar.FAB_ANIMATION_MODE_SCALE));

  setUpBottomAppBarShapeAppearance();

  return view;
}
 
Example 18
Source File: FragmentSetting.java    From BigApp_WordPress_Android with Apache License 2.0 4 votes vote down vote up
@Override
    public void findAndBindViews(View contentView) {
        setDefaultImageLeftVisible(true, R.attr.img_nav_back);
        setTitleText(R.string.v_left_menu_setting);

        View item_clear_cache, item_about, item_offline_download, item_font_size, item_img_mode, item_moon_toggle;
        item_clear_cache = contentView.findViewById(R.id.item_clear_cache);
        ((TextView) item_clear_cache.findViewById(R.id.tv_title)).setText(R.string.v_setting_item_clear_cache);
        tv_content_cache = (TextView) item_clear_cache.findViewById(R.id.tv_content);
        tv_content_cache.setText(DataManager.getMyCacheSize(mContext.getApplicationContext()));
        tv_content_cache.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.z_iv_arrow_right, 0);

        item_offline_download = contentView.findViewById(R.id.item_offline_download);
        ((TextView) item_offline_download.findViewById(R.id.tv_title)).setText(R.string.v_setting_item_offline_download);
        ((TextView) item_offline_download.findViewById(R.id.tv_content)).setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.z_iv_arrow_right, 0);

        item_about = contentView.findViewById(R.id.item_about);
        ((TextView) item_about.findViewById(R.id.tv_title)).setText(R.string.v_setting_item_about);
        ((TextView) item_about.findViewById(R.id.tv_content)).setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.z_iv_arrow_right, 0);

        item_font_size = contentView.findViewById(R.id.item_font_size);
        ((TextView) item_font_size.findViewById(R.id.tv_title)).setText(R.string.v_setting_item_font_size);

        item_img_mode = contentView.findViewById(R.id.item_img_mode);
        ((TextView) item_img_mode.findViewById(R.id.tv_title)).setText(R.string.v_setting_item_img_mode);
        tv_img_mode_content = (TextView) item_img_mode.findViewById(R.id.tv_content);
        setImgMode(SettingCache.getImgMode(mContext));

        item_moon_toggle = contentView.findViewById(R.id.item_moon_toggle);
        ((TextView) item_moon_toggle.findViewById(R.id.tv_title)).setText(R.string.v_setting_item_moon_toggle);
        ToggleButton moonBtn = (ToggleButton) item_moon_toggle.findViewById(R.id.btn_moon);

        moonBtn.setChecked(new SpTool(mContext, SpTool.SP_SETTING).getBoolean("moon", false));

        moonBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    BaseApplication.sDefaultImageDrawable = R.drawable.z_iv_default_y;
                } else {
                    BaseApplication.sDefaultImageDrawable = R.drawable.z_iv_default;
                }
                new SpTool(mContext, SpTool.SP_SETTING).putBoolean("moon", isChecked);
                setThemeType(isChecked);
                EventBus.getDefault().post(new MoonEvent(isChecked));
            }
        });

        item_clear_cache.setOnClickListener(this);
        item_about.setOnClickListener(this);
        item_offline_download.setOnClickListener(this);
        item_font_size.setOnClickListener(this);
        item_img_mode.setOnClickListener(this);

//        ((TextView) contentView.findViewById(R.id.tv_version)).setText(getString(R.string.v_version, CommonUtils.getVersionName(mContext)));
    }
 
Example 19
Source File: TestActivity.java    From BluetoothCameraAndroid with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);
    mSurfaceView = (SurfaceView) findViewById(R.id.surfaceview);
    mCameraOnOffBUtton = (ToggleButton) findViewById(R.id.camera_on_off_toggle);

    mImageView = (ImageView) findViewById(R.id.imageView);

    setCamera();
    setCameraOrientation();

    mBluetoothDevice = getIntent().getExtras().getParcelable("data");

    mBluetoothHandler = BluetoothHandler.newInstance(new BluetoothListener() {
        @Override
        public void onReceivedData(byte[] bytes) {

        }

        @Override
        public void onConnected(BluetoothDevice device) {
            mCamera.setPreviewCallback(TestActivity.this);
            mCamera.startPreview();
        }

        @Override
        public void connectionFailed() {

        }

        @Override
        public void onLostConnection() {

        }

        @Override
        public void onGotAck(String ack) {
            Log.e(TAG, ack);
            if (ack.equals(BluetoothHandler.ACK_INIT)) {
                mInitAck = true;
                mBluetoothHandler.write(mPendingImageBytes);
                mBluetoothHandler.write(BluetoothHandler.DATA_END.getBytes());
            } else if (ack.equals(BluetoothHandler.ACK_DATA_RECEIVED)) {
                mDataAck = true;
            }
        }
    }, false);

    mBluetoothHandler.start();
    mBluetoothHandler.connect(mBluetoothDevice);

    //This is to allow window to select pixel format by itself
    getWindow().setFormat(PixelFormat.UNKNOWN);

    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(this);

    //Deprecated and ignored(Values set automatically)
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mCameraOnOffBUtton.setOnCheckedChangeListener(this);


}
 
Example 20
Source File: PasswordEditText.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
public PasswordEditText(Context context, AttributeSet attrs) {
	super(context, attrs);

	// 方式1获取属性
	TypedArray a = context.obtainStyledAttributes(attrs,
			R.styleable.PasswordEditText);

	hintString = a
			.getString(R.styleable.PasswordEditText_PasswordEditText_hint);

	passwordEditTextToggle = a
			.getDrawable(R.styleable.PasswordEditText_PasswordEditText_toggle);

	hintColor = a.getColor(R.styleable.PasswordEditText_PasswordEditText_hint_color,getContext().getResources().getColor(R.color.gray_half_5));

	passwordEditTextIcon = a
			.getDrawable(R.styleable.PasswordEditText_PasswordEditText_icon);


	passwordEditTextBackground = a
			.getDrawable(R.styleable.PasswordEditText_PasswordEditText_background);

	a.recycle();

	View view = LayoutInflater.from(context).inflate(
			R.layout.password_edittext, null);

	tbPasswordEditTextToggle = (ToggleButton) view
			.findViewById(R.id.tb_password_eidttext_toggle);

	if (passwordEditTextToggle != null)
		tbPasswordEditTextToggle
				.setBackgroundDrawable(passwordEditTextToggle);

	et = (EditText) view.findViewById(R.id.et_password_eidttext_edittext);
	if (!TextUtils.isEmpty(hintString))
		et.setHint(hintString);

	et.setHintTextColor(hintColor);


	rl = (RelativeLayout) view
			.findViewById(R.id.rl);
	if(passwordEditTextBackground !=null)
		rl.setBackgroundDrawable(passwordEditTextBackground);

	ivPasswordEditTextIcon = (ImageView) view.findViewById(R.id.iv_with_del_eidttext_icon);
	if (passwordEditTextIcon != null)
		ivPasswordEditTextIcon
				.setImageDrawable(passwordEditTextIcon);




	tbPasswordEditTextToggle.setChecked(true);

	tbPasswordEditTextToggle
			.setOnCheckedChangeListener(new OnCheckedChangeListener() {

				@Override
				public void onCheckedChanged(CompoundButton buttonView,
						boolean isChecked) {

					if (!isChecked) {
						et.setTransformationMethod(HideReturnsTransformationMethod
								.getInstance());
					} else {
						et.setTransformationMethod(PasswordTransformationMethod
								.getInstance());
					}
					et.postInvalidate();

					Editable editable = et.getText();
					et.setSelection(editable.length());
				}
			});

	// ivPasswordEditTextToggle.setOnClickListener(new OnClickListener() {
	// @Override
	// public void onClick(View v) {
	//
	// if (tbPasswordEditTextToggle.isChecked()) {
	// et.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
	// } else {
	// et.setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL);
	// }
	// }
	// });
	// 给编辑框添加文本改变事件
	// et.addTextChangedListener(new MyTextWatcher());

	// 把获得的view加载到这个控件中
	addView(view);
}