Source:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getResources().getBoolean(R.bool.portrait_only)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } setContentView(R.layout.activity_login); setTitle(getString(R.string.txtSignIn)); setSupportActionBar(toolbar); if(getSupportActionBar()!=null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } userLoginUri = Uri.parse(getString(R.string.website) + "cgi/user.pl"); resetPasswordUri = Uri.parse(getString(R.string.website) + "cgi/reset_password.pl"); customTabActivityHelper = new CustomTabActivityHelper(); customTabActivityHelper.setConnectionCallback(this); customTabActivityHelper.mayLaunchUrl(userLoginUri, null, null); signup.setEnabled(true); final SharedPreferences settings = getSharedPreferences("login", 0); String loginS = settings.getString("user", getResources().getString(R.string.txt_anonymous)); if (loginS.equals("user")) { new MaterialDialog.Builder(this) .title(R.string.log_in) .content(R.string.login_true) .neutralText(R.string.ok_button) .show(); } apiClient = new Retrofit.Builder() .baseUrl(BuildConfig.HOST) .client(Utils.HttpClientBuilder()) .build() .create(OpenFoodAPIService.class); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mShakeDetector = new ShakeDetector(); SharedPreferences shakePreference = PreferenceManager.getDefaultSharedPreferences(this); scanOnShake = shakePreference.getBoolean("shakeScanMode", false); mShakeDetector.setOnShakeListener(new ShakeDetector.OnShakeDetected() { @Override public void onShake(int count) { if (scanOnShake) { Utils.scan(LoginActivity.this); } } }); }

Target:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getResources().getBoolean(R.bool.portrait_only)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } setContentView(R.layout.activity_login); setTitle(getString(R.string.txtSignIn)); setSupportActionBar(toolbar); if(getSupportActionBar()!=null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } userLoginUri = Uri.parse(getString(R.string.website) + "cgi/user.pl"); resetPasswordUri = Uri.parse(getString(R.string.website) + "cgi/reset_password.pl"); customTabActivityHelper = new CustomTabActivityHelper(); customTabActivityHelper.setConnectionCallback(this); customTabActivityHelper.mayLaunchUrl(userLoginUri, null, null); signup.setEnabled(true); final SharedPreferences settings = getSharedPreferences("login", 0); String loginS = settings.getString(getResources().getString(R.string.user), getResources().getString(R.string.txt_anonymous)); if (loginS.equals(getResources().getString(R.string.user))) { new MaterialDialog.Builder(this) .title(R.string.log_in) .content(R.string.login_true) .neutralText(R.string.ok_button) .show(); } apiClient = new Retrofit.Builder() .baseUrl(BuildConfig.HOST) .client(Utils.HttpClientBuilder()) .build() .create(OpenFoodAPIService.class); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mShakeDetector = new ShakeDetector(); SharedPreferences shakePreference = PreferenceManager.getDefaultSharedPreferences(this); scanOnShake = shakePreference.getBoolean("shakeScanMode", false); mShakeDetector.setOnShakeListener(new ShakeDetector.OnShakeDetected() { @Override public void onShake(int count) { if (scanOnShake) { Utils.scan(LoginActivity.this); } } }); }