diff --git a/app/build.gradle b/app/build.gradle index 4b0cdfd1..ed00346a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,6 +3,9 @@ apply plugin: 'com.android.application' android { compileSdkVersion 28 buildToolsVersion "29.0.2" + dataBinding { + enabled = true + } defaultConfig { applicationId "com.android.onyx.demo" minSdkVersion 23 @@ -58,7 +61,6 @@ dependencies { implementation "com.android.support:multidex:1.0.3" api "com.android.support.constraint:constraint-layout:1.1.3" - implementation 'com.jakewharton:butterknife:7.0.1' annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:4.2.4" implementation "com.github.Raizlabs.DBFlow:dbflow-core:4.2.4" diff --git a/app/src/main/java/com/android/onyx/demo/AppOptimizeActivity.java b/app/src/main/java/com/android/onyx/demo/AppOptimizeActivity.java index ad0d6b41..569db449 100644 --- a/app/src/main/java/com/android/onyx/demo/AppOptimizeActivity.java +++ b/app/src/main/java/com/android/onyx/demo/AppOptimizeActivity.java @@ -8,7 +8,12 @@ import android.widget.Button; import android.widget.EditText; + +import androidx.databinding.DataBindingUtil; + + import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityAppOptimizeBinding; /** * Created by Administrator on 2018/3/26 17:35. @@ -18,39 +23,31 @@ public class AppOptimizeActivity extends Activity { private EditText etIsFull; private EditText etPkgName; private Button btnSendBroadcast; + private ActivityAppOptimizeBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_app_optimize); - initView(); - initListener(); - } + binding = DataBindingUtil.setContentView(this, R.layout.activity_app_optimize); + - private void initView(){ - etIsFull = (EditText) findViewById(R.id.et_isfull); - etPkgName = (EditText) findViewById(R.id.et_pkgname); - btnSendBroadcast = (Button) findViewById(R.id.btn_send_broadcast); } - private void initListener(){ - btnSendBroadcast.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - boolean isfull; - String isfullTxt = etIsFull.getText().toString(); - if(isfullTxt.equals("false")){ - isfull = false; - }else{ - isfull = true; - } - String pkgnameTxt = etPkgName.getText().toString(); - Intent intent = new Intent(); - intent.setAction("com.onyx.app.optimize.setting"); - intent.putExtra("optimize_fullScreen",isfull); - intent.putExtra("optimize_pkgName",pkgnameTxt); - sendBroadcast(intent); - } - }); + public void onClick(View v) { + boolean isfull; + String isfullTxt = etIsFull.getText().toString(); + if (isfullTxt.equals("false")) { + isfull = false; + } else { + isfull = true; + } + String pkgnameTxt = etPkgName.getText().toString(); + Intent intent = new Intent(); + intent.setAction("com.onyx.app.optimize.setting"); + intent.putExtra("optimize_fullScreen", isfull); + intent.putExtra("optimize_pkgName", pkgnameTxt); + sendBroadcast(intent); } + } + diff --git a/app/src/main/java/com/android/onyx/demo/DictionaryActivity.java b/app/src/main/java/com/android/onyx/demo/DictionaryActivity.java index 37004377..0d52e1c3 100644 --- a/app/src/main/java/com/android/onyx/demo/DictionaryActivity.java +++ b/app/src/main/java/com/android/onyx/demo/DictionaryActivity.java @@ -12,7 +12,10 @@ import android.widget.EditText; import android.widget.TextView; +import androidx.databinding.DataBindingUtil; + import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityDictqueryBinding; import com.onyx.android.sdk.data.DictionaryQuery; import com.onyx.android.sdk.utils.DictionaryUtil; @@ -22,15 +25,15 @@ * Created by seeksky on 2018/5/17. */ -public class DictionaryActivity extends AppCompatActivity implements View.OnClickListener{ - private EditText editText; - private Button buttonQuery; - private TextView textViewDisplay; +public class DictionaryActivity extends AppCompatActivity { + + private ActivityDictqueryBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_dictquery); + binding = DataBindingUtil.setContentView(this, R.layout.activity_dictquery); + binding.setActivityDictQuery(this); initView(); } @@ -40,20 +43,16 @@ protected void onDestroy() { } private void initView() { - editText = (EditText) findViewById(R.id.edittext_keyword); - buttonQuery = (Button) findViewById(R.id.button_query); - textViewDisplay = (TextView) findViewById(R.id.textview_query_result); - textViewDisplay.setMovementMethod(ScrollingMovementMethod.getInstance()); - buttonQuery.setOnClickListener(this); + binding.textviewQueryResult.setMovementMethod(ScrollingMovementMethod.getInstance()); + } - @Override public void onClick(View v) { - doQueryJob(editText.getText().toString()); + doQueryJob(binding.edittextKeyword.getText().toString()); } private void doQueryJob(final String keyword) { - textViewDisplay.setText(""); + binding.textviewQueryResult.setText(""); hideSoftKeyboard(); new AsyncTask() { @Override @@ -71,9 +70,9 @@ protected void onPostExecute(DictionaryQuery dictionaryQuery) { } for (DictionaryQuery.Dictionary dictionary : list) { System.out.println("dictionary = " + dictionary.getExplanation()); - textViewDisplay.append(dictionary.getDictName() + "\n"); - textViewDisplay.append(dictionary.getExplanation()); - textViewDisplay.append("\n=============================\n"); + binding.textviewQueryResult.append(dictionary.getDictName() + "\n"); + binding.textviewQueryResult.append(dictionary.getExplanation()); + binding.textviewQueryResult.append("\n=============================\n"); } } } @@ -83,7 +82,7 @@ protected void onPostExecute(DictionaryQuery dictionaryQuery) { private void hideSoftKeyboard() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { - imm.hideSoftInputFromWindow(buttonQuery.getWindowToken(),0); + imm.hideSoftInputFromWindow(binding.buttonQuery.getWindowToken(), 0); } } } diff --git a/app/src/main/java/com/android/onyx/demo/EacDemoActivity.java b/app/src/main/java/com/android/onyx/demo/EacDemoActivity.java index dc4dfe28..c1a00056 100644 --- a/app/src/main/java/com/android/onyx/demo/EacDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/EacDemoActivity.java @@ -7,42 +7,30 @@ import android.widget.CheckBox; import android.widget.TextView; +import androidx.databinding.DataBindingUtil; + import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityEacDemoBinding; import com.onyx.android.sdk.api.device.eac.SimpleEACManage; import com.onyx.android.sdk.rx.RxUtils; import java.util.concurrent.Callable; -import butterknife.Bind; -import butterknife.ButterKnife; + import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; /** * App optimize entrance:long press app to select the optimization option or FloatingButton optimization option. */ -public class EacDemoActivity extends AppCompatActivity implements View.OnClickListener { - @Bind(R.id.hook_epdc_status) - TextView hookEpdcStatus; - @Bind(R.id.eac_enable_status) - TextView eacEnableStatus; - @Bind(R.id.eac_support_status) - TextView eacSupportStatus; - @Bind(R.id.allow_eac) - Button allowEAC; - @Bind(R.id.disallow_eac) - Button disallowEAC; - @Bind(R.id.update_status) - Button updateStatus; - @Bind(R.id.cb_refresh_config_enable) - CheckBox cbRefreshConfigEnable; + +public class EacDemoActivity extends AppCompatActivity { + private ActivityEacDemoBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_eac_demo); - ButterKnife.bind(this); - initView(); + binding = DataBindingUtil.setContentView(this, R.layout.activity_eac_demo); initData(); } @@ -50,14 +38,6 @@ private void initData() { updateAllStatus(); } - private void initView() { - allowEAC.setOnClickListener(this); - disallowEAC.setOnClickListener(this); - updateStatus.setOnClickListener(this); - cbRefreshConfigEnable.setOnClickListener(this); - } - - @Override public void onClick(View v) { switch (v.getId()) { case R.id.allow_eac: @@ -79,7 +59,7 @@ public void onClick(View v) { */ private void toggleRefreshConfig() { RxUtils.runInIO(() -> { - boolean enable = cbRefreshConfigEnable.isChecked(); + boolean enable = binding.cbRefreshConfigEnable.isChecked(); SimpleEACManage.getInstance().setEACRefreshConfigEnable(EacDemoActivity.this, enable); updateRefreshConfigEnableStatus(); }); @@ -111,7 +91,7 @@ public Boolean call() throws Exception { }, new Consumer() { @Override public void accept(Boolean enable) throws Exception { - eacEnableStatus.setText(getString(R.string.eac_enable_format, enable + "")); + binding.eacEnableStatus.setText(getString(R.string.eac_enable_format, enable + "")); } }, Schedulers.io()); } @@ -125,7 +105,7 @@ public Boolean call() throws Exception { }, new Consumer() { @Override public void accept(Boolean enable) throws Exception { - hookEpdcStatus.setText(getString(R.string.hook_epdc_format, enable + "")); + binding.hookEpdcStatus.setText(getString(R.string.hook_epdc_format, enable + "")); } }, Schedulers.io()); } @@ -139,14 +119,14 @@ public Boolean call() throws Exception { }, new Consumer() { @Override public void accept(Boolean support) throws Exception { - eacSupportStatus.setText(getString(R.string.eac_support_format, support + "")); + binding.eacSupportStatus.setText(getString(R.string.eac_support_format, support + "")); } }, Schedulers.io()); } private void updateRefreshConfigEnableStatus() { RxUtils.runWith(() -> SimpleEACManage.getInstance().isEACRefreshConfigEnable(getPackageName()), - enable -> cbRefreshConfigEnable.setChecked(enable), + enable -> binding.cbRefreshConfigEnable.setChecked(enable), Schedulers.io()); } diff --git a/app/src/main/java/com/android/onyx/demo/EnvironmentDemoActivity.java b/app/src/main/java/com/android/onyx/demo/EnvironmentDemoActivity.java index ab9815bb..fa168e65 100644 --- a/app/src/main/java/com/android/onyx/demo/EnvironmentDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/EnvironmentDemoActivity.java @@ -5,19 +5,22 @@ import android.support.v7.app.AppCompatActivity; import android.widget.TextView; +import androidx.databinding.DataBindingUtil; + import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityEnvironmentDemoBinding; import com.onyx.android.sdk.api.device.DeviceEnvironment; public class EnvironmentDemoActivity extends AppCompatActivity { + private ActivityEnvironmentDemoBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_environment_demo); - - ((TextView)findViewById(R.id.text_view_flash_path)).setText(Environment.getExternalStorageDirectory().getAbsolutePath()); - ((TextView)findViewById(R.id.text_view_flash_state)).setText(Environment.getExternalStorageState()); + binding = DataBindingUtil.setContentView(this, R.layout.activity_environment_demo); - ((TextView)findViewById(R.id.text_view_sd_card_path)).setText(DeviceEnvironment.getRemovableSDCardDirectory().getAbsolutePath()); + binding.textViewFlashPath.setText(Environment.getExternalStorageDirectory().getAbsolutePath()); + binding.textViewFlashState.setText(Environment.getExternalStorageState()); + binding.textViewSdCardPath.setText(DeviceEnvironment.getRemovableSDCardDirectory().getAbsolutePath()); } } diff --git a/app/src/main/java/com/android/onyx/demo/EpdDemoActivity.java b/app/src/main/java/com/android/onyx/demo/EpdDemoActivity.java index 6873fdc8..f48d6d83 100644 --- a/app/src/main/java/com/android/onyx/demo/EpdDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/EpdDemoActivity.java @@ -2,96 +2,59 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; -import android.view.SurfaceView; + import android.view.View; -import android.widget.Button; -import android.widget.RelativeLayout; -import android.widget.TextView; + + +import androidx.databinding.DataBindingUtil; import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityEpdDemoBinding; import com.onyx.android.sdk.api.device.EpdDeviceManager; import com.onyx.android.sdk.api.device.epd.EpdController; import com.onyx.android.sdk.api.device.epd.UpdateMode; -import butterknife.Bind; -import butterknife.ButterKnife; - -public class EpdDemoActivity extends AppCompatActivity implements View.OnClickListener { +public class EpdDemoActivity extends AppCompatActivity { + private ActivityEpdDemoBinding binding; private static final String TAG = EpdDemoActivity.class.getSimpleName(); - @Bind(R.id.button_partial_update) - Button button_partial_update; - @Bind(R.id.button_regal_partial) - Button button_regal_partial; - @Bind(R.id.button_enter_fast_mode) - Button button_enter_fast_mode; - @Bind(R.id.button_quit_fast_mode) - Button button_quit_fast_mode; - @Bind(R.id.button_screen_refresh) - Button button_screen_refresh; - @Bind(R.id.textview) - TextView textView; - @Bind(R.id.surfaceview) - SurfaceView surfaceView; - @Bind(R.id.button_enter_x_mode) - Button button_enter_x_mode; - @Bind(R.id.activity_main) - RelativeLayout activityMain; - @Bind(R.id.button_enter_normal_mode) - Button button_enter_normal_mode; - @Bind(R.id.button_enter_A2_mode) - Button button_enter_A2_mode; - @Bind(R.id.button_enter_du_mode) - Button button_enter_du_mode; + private boolean isFastMode = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_epd_demo); - - ButterKnife.bind(this); - button_partial_update.setOnClickListener(this); - button_regal_partial.setOnClickListener(this); - button_enter_fast_mode.setOnClickListener(this); - button_quit_fast_mode.setOnClickListener(this); - button_screen_refresh.setOnClickListener(this); - button_enter_x_mode.setOnClickListener(this); - button_enter_normal_mode.setOnClickListener(this); - button_enter_A2_mode.setOnClickListener(this); - button_enter_du_mode.setOnClickListener(this); - + binding = DataBindingUtil.setContentView(this, R.layout.activity_epd_demo); // set full update after how many partial update EpdDeviceManager.setGcInterval(5); } - @Override public void onClick(View v) { - if (v.equals(button_partial_update)) { + if (v.equals(binding.buttonPartialUpdate)) { updateTextView(); - EpdDeviceManager.applyWithGCIntervalWithoutRegal(textView); - } else if (v.equals(button_regal_partial)) { + EpdDeviceManager.applyWithGCIntervalWithoutRegal(binding.textview); + } else if (v.equals(binding.buttonRegalPartial)) { updateTextView(); - EpdDeviceManager.applyWithGCIntervalWitRegal(textView, true); - } else if (v.equals(button_screen_refresh)) { + EpdDeviceManager.applyWithGCIntervalWitRegal(binding.textview, true); + } else if (v.equals(binding.buttonScreenRefresh)) { updateTextView(); EpdController.repaintEveryThing(UpdateMode.GC); - } else if (v.equals(button_enter_fast_mode)) { + } else if (v.equals(binding.buttonEnterFastMode)) { isFastMode = true; EpdDeviceManager.enterAnimationUpdate(true); - } else if (v.equals(button_quit_fast_mode)) { + } else if (v.equals(binding.buttonQuitFastMode)) { EpdDeviceManager.exitAnimationUpdate(true); isFastMode = false; - } else if (v.equals(button_enter_x_mode)) { + } else if (v.equals(binding.buttonEnterXMode)) { EpdController.clearAppScopeUpdate(); EpdController.applyAppScopeUpdate(TAG, true, true, UpdateMode.ANIMATION_X, Integer.MAX_VALUE); - } else if (v.equals(button_enter_A2_mode)) { + } else if (v.equals(binding.buttonEnterA2Mode)) { EpdController.clearAppScopeUpdate(); EpdController.applyAppScopeUpdate(TAG, true, true, UpdateMode.ANIMATION_QUALITY, Integer.MAX_VALUE); - } else if (v.equals(button_enter_normal_mode)) { + } else if (v.equals(binding.buttonEnterNormalMode)) { EpdController.clearAppScopeUpdate(); EpdController.applyAppScopeUpdate(TAG, false, true, UpdateMode.None, Integer.MAX_VALUE); - } else if (v.equals(button_enter_du_mode)) { + } else if (v.equals(binding.buttonEnterDuMode)) { EpdController.clearAppScopeUpdate(); EpdController.applyAppScopeUpdate(TAG, true, true, UpdateMode.DU_QUALITY, Integer.MAX_VALUE); } @@ -99,8 +62,8 @@ public void onClick(View v) { private void updateTextView() { StringBuilder sb = new StringBuilder(); - sb.append(textView.getText()); + sb.append(binding.textview.getText()); sb.append("hello world!"); - textView.setText(sb.toString()); + binding.textview.setText(sb.toString()); } } diff --git a/app/src/main/java/com/android/onyx/demo/FrontLightDemoActivity.java b/app/src/main/java/com/android/onyx/demo/FrontLightDemoActivity.java index a64cc6bf..a76b952c 100644 --- a/app/src/main/java/com/android/onyx/demo/FrontLightDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/FrontLightDemoActivity.java @@ -4,63 +4,41 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; -import android.widget.TextView; + + +import androidx.databinding.DataBindingUtil; import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityFrontLightDemoBinding; import com.onyx.android.sdk.api.device.FrontLightController; import com.onyx.android.sdk.device.BaseDevice; -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnClick; public class FrontLightDemoActivity extends AppCompatActivity { - - @Bind({R.id.ctm_cover}) - View ctmCover; - @Bind({R.id.fl_cover}) - View flCover; - @Bind({R.id.light_value}) - TextView lightValue; - @Bind({R.id.warm_light_value}) - TextView warmLightValue; - @Bind({R.id.cold_light_value}) - TextView coldLightValue; + private ActivityFrontLightDemoBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_front_light_demo); - - ButterKnife.bind(this); + binding = DataBindingUtil.setContentView(this, R.layout.activity_front_light_demo); initView(); + binding.setActivityFrontlight(this); } private void initView() { if (FrontLightController.hasCTMBrightness(this)) { - warmLightValue.setText("Current value:" + FrontLightController.getWarmLightConfigValue(this)); - coldLightValue.setText("Current value:" + FrontLightController.getColdLightConfigValue(this)); - flCover.setVisibility(View.VISIBLE); - flCover.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - } - }); + binding.warmLightValue.setText("Current value:" + FrontLightController.getWarmLightConfigValue(this)); + binding.coldLightValue.setText("Current value:" + FrontLightController.getColdLightConfigValue(this)); + binding.flCover.setVisibility(View.VISIBLE); + } else if (FrontLightController.hasFLBrightness(this)) { - lightValue.setText("Current value:" + FrontLightController.getBrightness(this)); - ctmCover.setVisibility(View.VISIBLE); - ctmCover.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - } - }); + binding.lightValue.setText("Current value:" + FrontLightController.getBrightness(this)); + binding.ctmCover.setVisibility(View.VISIBLE); + } } - @OnClick(R.id.warm_light_toggle) - public void toggleWarmLight() { + public void toggleWarmLight(View view) { if (FrontLightController.isWarmLightOn(this)) { FrontLightController.closeWarmLight(); } else { @@ -68,18 +46,15 @@ public void toggleWarmLight() { } } - @OnClick(R.id.warm_light_increase) - public void increaseWarmLight() { + public void increaseWarmLight(View view) { increaseBrightness(FrontLightController.LIGHT_TYPE_CTM_WARM); } - @OnClick(R.id.warm_light_decrease) - public void decreaseWarmLight() { + public void decreaseWarmLight(View view) { decreaseBrightness(FrontLightController.LIGHT_TYPE_CTM_WARM); } - @OnClick(R.id.cold_light_toggle) - public void toggleColdLight() { + public void toggleColdLight(View view) { if (FrontLightController.isColdLightOn(this)) { FrontLightController.closeColdLight(); } else { @@ -87,23 +62,19 @@ public void toggleColdLight() { } } - @OnClick(R.id.update_warm_light_value) - public void updateWarmLightValue() { - warmLightValue.setText("Current value:" + FrontLightController.getWarmLightConfigValue(this)); + public void updateWarmLightValue(View view) { + binding.warmLightValue.setText("Current value:" + FrontLightController.getWarmLightConfigValue(this)); } - @OnClick(R.id.cold_light_increase) - public void increaseColdLight() { + public void increaseColdLight(View view) { increaseBrightness(FrontLightController.LIGHT_TYPE_CTM_COLD); } - @OnClick(R.id.cold_light_decrease) - public void decreaseColdLight() { + public void decreaseColdLight(View view) { decreaseBrightness(FrontLightController.LIGHT_TYPE_CTM_COLD); } - @OnClick(R.id.button_light_toggle) - public void toggleFLLight() { + public void toggleFLLight(View view) { if (FrontLightController.isLightOn(this, BaseDevice.LIGHT_TYPE_FL)) { FrontLightController.turnOff(this); } else { @@ -111,29 +82,24 @@ public void toggleFLLight() { } } - @OnClick(R.id.update_cold_light_value) - public void updateColdLightValue() { - coldLightValue.setText("Current value:" + FrontLightController.getColdLightConfigValue(this)); + public void updateColdLightValue(View view) { + binding.coldLightValue.setText("Current value:" + FrontLightController.getColdLightConfigValue(this)); } - @OnClick(R.id.button_light_darker) - public void decreaseFLLight() { + public void decreaseFLLight(View view) { decreaseBrightness(FrontLightController.LIGHT_TYPE_FL); } - @OnClick(R.id.button_light_lighter) - public void increaseFLLight() { + public void increaseFLLight(View view) { increaseBrightness(FrontLightController.LIGHT_TYPE_FL); } - @OnClick(R.id.button_show_brightness_setting) - public void ShowBrightnessSetting() { + public void ShowBrightnessSetting(View view) { sendBroadcast(new Intent("action.show.brightness.dialog")); } - @OnClick(R.id.update_light_value) - public void updateLightValue() { - lightValue.setText("Current value:" + FrontLightController.getBrightness(this)); + public void updateLightValue(View view) { + binding.lightValue.setText("Current value:" + FrontLightController.getBrightness(this)); } public void increaseBrightness(int colorTemp) { diff --git a/app/src/main/java/com/android/onyx/demo/FullScreenDemoActivity.java b/app/src/main/java/com/android/onyx/demo/FullScreenDemoActivity.java index cb9f186d..0a13e4cf 100644 --- a/app/src/main/java/com/android/onyx/demo/FullScreenDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/FullScreenDemoActivity.java @@ -3,33 +3,26 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; -import android.widget.Button; + +import androidx.databinding.DataBindingUtil; import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityFullScreenDemoBinding; import com.onyx.android.sdk.utils.DeviceUtils; -import butterknife.Bind; -import butterknife.ButterKnife; - -public class FullScreenDemoActivity extends AppCompatActivity implements View.OnClickListener { - @Bind(R.id.button_full_screen) - Button buttonFullScreen; +public class FullScreenDemoActivity extends AppCompatActivity { + private ActivityFullScreenDemoBinding binding; - @Override protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); - setContentView(R.layout.activity_full_screen_demo); + binding = DataBindingUtil.setContentView(this, R.layout.activity_full_screen_demo); - ButterKnife.bind(this); - buttonFullScreen.setOnClickListener(this); } - @Override - public void onClick(View v) { - if (v.equals(buttonFullScreen)) { - boolean fullscreen = !DeviceUtils.isFullScreen(this); - DeviceUtils.setFullScreenOnResume(this, fullscreen); - } + public void switchFullScreen(View v) { + boolean fullscreen = !DeviceUtils.isFullScreen(this); + DeviceUtils.setFullScreenOnResume(this, fullscreen); } } diff --git a/app/src/main/java/com/android/onyx/demo/MainActivity.java b/app/src/main/java/com/android/onyx/demo/MainActivity.java index 865e2400..74e669cb 100644 --- a/app/src/main/java/com/android/onyx/demo/MainActivity.java +++ b/app/src/main/java/com/android/onyx/demo/MainActivity.java @@ -5,97 +5,84 @@ import android.support.v7.app.AppCompatActivity; import android.view.View; +import androidx.databinding.DataBindingUtil; + import com.android.onyx.demo.scribble.ScribbleDemoActivity; import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityMainBinding; import com.onyx.android.sdk.api.device.epd.EpdController; -import butterknife.ButterKnife; -import butterknife.OnClick; public class MainActivity extends AppCompatActivity { + private ActivityMainBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - ButterKnife.bind(this); - final View view = findViewById(android.R.id.content); + binding = DataBindingUtil.setContentView(this, R.layout.activity_main); + final View view = binding.getRoot(); + binding.setActivityMain(this); EpdController.enablePost(view, 1); } - - @OnClick(R.id.button_epd) - public void button_epd() { + public void button_epd(View view) { go(EpdDemoActivity.class); } - @OnClick(R.id.button_front_light) - public void button_front_light() { + public void button_front_light(View view) { go(FrontLightDemoActivity.class); } - @OnClick(R.id.button_full_screen) - public void button_full_screen() { + public void button_full_screen(View view) { go(FullScreenDemoActivity.class); } - @OnClick(R.id.button_environment) - public void button_environment() { + public void button_environment(View view) { go(EnvironmentDemoActivity.class); } - @OnClick(R.id.button_scribble_demo) - public void button_scribble_demo() { + public void button_scribble_demo(View view) { go(ScribbleDemoActivity.class); } - @OnClick(R.id.btn_dict_query) - public void btn_dict_query(){ + public void btn_dict_query(View view) { go(DictionaryActivity.class); } - - @OnClick(R.id.button_reader) - public void btn_reader() { + + public void btn_reader(View view) { go(ReaderDemoActivity.class); } - @OnClick(R.id.btn_screen_saver) - public void btn_screen_saver() { + public void btn_screen_saver(View view) { go(ScreensaverActivity.class); } - @OnClick(R.id.btn_open_setting) - public void btn_open_setting() { + public void btn_open_setting(View view) { go(OpenSettingActivity.class); } - @OnClick(R.id.btn_webview_optimize) - public void btn_webview_optimize() { + public void btn_webview_optimize(View view) { go(WebViewOptimizeActivity.class); } - @OnClick(R.id.btn_open_kcb) - public void btn_open_kcb() { + public void btn_open_kcb(View view) { go(OpenKcbActivity.class); } - @OnClick(R.id.btn_open_ota) - public void btn_open_ota() { + public void btn_open_ota(View view) { go(OTADemoActivity.class); } - @OnClick(R.id.button_refresh_mode) - public void onClickButtonRefreshMode() { + public void onClickButtonRefreshMode(View view) { go(RefreshModeDemoActivity.class); } - @OnClick(R.id.button_eac) - public void onClickButtonEacDemo() { + public void onClickButtonEacDemo(View view) { go(EacDemoActivity.class); } - private void go(Class activityClass){ + private void go(Class activityClass) { startActivity(new Intent(this, activityClass)); } + } diff --git a/app/src/main/java/com/android/onyx/demo/OTADemoActivity.java b/app/src/main/java/com/android/onyx/demo/OTADemoActivity.java index 9cd7a3f2..d5225796 100644 --- a/app/src/main/java/com/android/onyx/demo/OTADemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/OTADemoActivity.java @@ -3,10 +3,14 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; +import android.view.View; import android.widget.EditText; -import android.widget.TextView; + + +import androidx.databinding.DataBindingUtil; import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityOtaDemoBinding; import com.onyx.android.sdk.api.data.model.FirmwareBean; import com.onyx.android.sdk.api.device.OTAManager; import com.onyx.android.sdk.rx.RxUtils; @@ -14,9 +18,6 @@ import java.util.concurrent.Callable; -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnClick; import io.reactivex.functions.Consumer; /** @@ -24,16 +25,13 @@ */ public class OTADemoActivity extends AppCompatActivity { - - @Bind(R.id.tv_firmware_info) - public TextView tvFirmwareInfo; + private ActivityOtaDemoBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_ota_demo); - ButterKnife.bind(this); - + binding = DataBindingUtil.setContentView(this, R.layout.activity_ota_demo); + binding.setActivityOta(this); initData(); } @@ -47,7 +45,7 @@ public FirmwareBean call() throws Exception { @Override public void accept(FirmwareBean firmwareBean) throws Exception { if (firmwareBean != null) { - tvFirmwareInfo.setText(JSONUtils.toJson(firmwareBean)); + binding.tvFirmwareInfo.setText(JSONUtils.toJson(firmwareBean)); } } }); @@ -58,10 +56,8 @@ protected void onDestroy() { super.onDestroy(); } - - @OnClick(R.id.button_ota_update) - public void onOTAUpdate() { - EditText editText = findViewById(R.id.edittext_ota_package_path); + public void onOTAUpdate(View view) { + EditText editText = binding.edittextOtaPackagePath; String path = editText.getText().toString(); OTAManager.startFirmwareUpdate(this, path); } diff --git a/app/src/main/java/com/android/onyx/demo/OpenKcbActivity.java b/app/src/main/java/com/android/onyx/demo/OpenKcbActivity.java index 5a484bce..69e1e6ed 100644 --- a/app/src/main/java/com/android/onyx/demo/OpenKcbActivity.java +++ b/app/src/main/java/com/android/onyx/demo/OpenKcbActivity.java @@ -5,17 +5,17 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; -import android.widget.EditText; -import android.widget.RadioGroup; +import android.view.View; + import android.widget.Toast; +import androidx.databinding.DataBindingUtil; + import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityOpenKcbBinding; import com.onyx.android.sdk.utils.JSONUtils; import com.onyx.android.sdk.utils.StringUtils; -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnClick; /** * Created by zhilun on 2019/4/4. @@ -46,67 +46,55 @@ public TabIntentData setAction(TabAction action) { } } - @Bind(R.id.et_storage_jump_path) - EditText etStorageJumpPath; - - @Bind(R.id.rg_note) - RadioGroup rgNoteShop; + private ActivityOpenKcbBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_open_kcb); - ButterKnife.bind(this); + binding = DataBindingUtil.setContentView(this, R.layout.activity_open_kcb); + binding.setActivityOpenKcb(this); } - @OnClick(R.id.btn_open_library) - public void openLibrary() { + public void openLibrary(View view) { openModule(new TabIntentData().setAction(TabAction.OPEN_HOME)); } - @OnClick(R.id.btn_open_shop) - public void openShop() { + public void openShop(View view) { openModule(new TabIntentData().setAction(TabAction.OPEN_SHOP)); } - @OnClick(R.id.btn_open_note) - public void openNote() { + public void openNote(View view) { openModule(setNoteJumpPath(new TabIntentData().setAction(TabAction.OPEN_NOTE))); } - @OnClick(R.id.btn_open_storage) - public void openStorage() { + public void openStorage(View view) { TabIntentData data = new TabIntentData().setAction(TabAction.OPEN_STORAGE); - String jumpPath = etStorageJumpPath.getText().toString(); + String jumpPath = binding.etStorageJumpPath.getText().toString(); if (!StringUtils.isNullOrEmpty(jumpPath)) { data.setJumpPath(jumpPath); } openModule(data); } - @OnClick(R.id.btn_open_apps) - public void openApps() { + public void openApps(View view) { openModule(new TabIntentData().setAction(TabAction.OPEN_APPS)); } - @OnClick(R.id.btn_open_setting) - public void openSetting() { + public void openSetting(View view) { openModule(new TabIntentData().setAction(TabAction.OPEN_SETTING)); } - @OnClick(R.id.btn_open_application_management) - public void openApplicationManagement() { + public void openApplicationManagement(View view) { openModule(new TabIntentData().setAction(TabAction.OPEN_APPLICATION_MANAGEMENT)); } - @OnClick(R.id.btn_open_account_management) - public void openAccountManagement() { + public void openAccountManagement(View view) { openModule(new TabIntentData().setAction(TabAction.OPEN_ACCOUNT_MANAGER)); } private TabIntentData setNoteJumpPath(TabIntentData data) { String jumpPath = ""; - switch (rgNoteShop.getCheckedRadioButtonId()) { + switch (binding.rgNote.getCheckedRadioButtonId()) { case R.id.rb_search: jumpPath = NoteRouter.SEARCH.toString(); break; diff --git a/app/src/main/java/com/android/onyx/demo/OpenSettingActivity.java b/app/src/main/java/com/android/onyx/demo/OpenSettingActivity.java index b5112850..7787f975 100644 --- a/app/src/main/java/com/android/onyx/demo/OpenSettingActivity.java +++ b/app/src/main/java/com/android/onyx/demo/OpenSettingActivity.java @@ -4,36 +4,31 @@ import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; -import android.widget.Button; +import android.view.View; + import android.widget.Toast; +import androidx.databinding.DataBindingUtil; + import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityOpenSettingBinding; -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnClick; public class OpenSettingActivity extends AppCompatActivity { - - @Bind(R.id.btn_open_network) - Button btnOpenNetwork; - @Bind(R.id.btn_open_date_time) - Button btnOpenDateTime; + private ActivityOpenSettingBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_open_setting); - ButterKnife.bind(this); + binding = DataBindingUtil.setContentView(this, R.layout.activity_open_setting); + binding.setActivityOpenSetting(this); } - @OnClick(R.id.btn_open_network) - public void openNetwork() { + public void openNetwork(View view) { openActivity("com.onyx", "com.onyx.setting.ui.SettingContainerActivity", "onyx.settings.action.network"); } - @OnClick(R.id.btn_open_date_time) - public void openDateTime() { + public void openDateTime(View view) { openActivity("com.onyx", "com.onyx.setting.ui.SettingContainerActivity", "onyx.settings.action.datetime"); } diff --git a/app/src/main/java/com/android/onyx/demo/ReaderDemoActivity.java b/app/src/main/java/com/android/onyx/demo/ReaderDemoActivity.java index 9c3bf3d4..e3798924 100644 --- a/app/src/main/java/com/android/onyx/demo/ReaderDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/ReaderDemoActivity.java @@ -11,19 +11,19 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.content.FileProvider; -import android.widget.EditText; -import android.widget.TextView; +import android.view.View; + import android.widget.Toast; +import androidx.databinding.DataBindingUtil; + import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityReaderDemoBinding; import com.onyx.android.sdk.utils.FileUtils; import com.onyx.android.sdk.utils.StringUtils; import java.io.File; -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnClick; /** * Created by Administrator on 2018/4/25 17:23. @@ -32,20 +32,16 @@ public class ReaderDemoActivity extends Activity { private static final String READER_PROVIDER = "content://com.onyx.content.database.ContentProvider/Metadata"; - @Bind(R.id.et_file) - EditText etFile; - @Bind({R.id.textView_progress}) - TextView tvProgress; + private ActivityReaderDemoBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_reader_demo); - ButterKnife.bind(this); + binding = DataBindingUtil.setContentView(this, R.layout.activity_reader_demo); + binding.setActivityReader(this); } - @OnClick(R.id.btn_open) - public void btn_open() { + public void btn_open(View view) { if (!FilePathValidation()) { return; } @@ -54,7 +50,7 @@ public void btn_open() { intent.setComponent(componentName); intent.setData(FileProvider.getUriForFile(this, getPackageName() + ".onyx.fileprovider", - new File(etFile.getText().toString()))); + new File(binding.etFile.getText().toString()))); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); ComponentName result = startService(intent); @@ -63,21 +59,19 @@ public void btn_open() { } } - @OnClick(R.id.btn_query_progress) - public void btn_query_progress() { + public void btn_query_progress(View view) { if (!FilePathValidation()) { return; } - String progress = queryByPath(etFile.getText().toString()); + String progress = queryByPath(binding.etFile.getText().toString()); if (!StringUtils.isNullOrEmpty(progress)) { - tvProgress.setText(getString(R.string.reading_progress, progress)); + binding.textViewProgress.setText(getString(R.string.reading_progress, progress)); } else { Toast.makeText(getApplicationContext(), R.string.query_fail, Toast.LENGTH_SHORT).show(); } } - @OnClick(R.id.btn_delete_reader_data) - public void btn_delete_reader_data() { + public void btn_delete_reader_data(View view) { if (!FilePathValidation()) { return; } @@ -114,7 +108,7 @@ public String queryByPath(String path) { } private boolean FilePathValidation() { - String filePath = etFile.getText().toString(); + String filePath = binding.etFile.getText().toString(); if ("".equals(filePath)) { Toast.makeText(this, R.string.enter_book_path, Toast.LENGTH_SHORT).show(); return false; diff --git a/app/src/main/java/com/android/onyx/demo/RefreshModeDemoActivity.java b/app/src/main/java/com/android/onyx/demo/RefreshModeDemoActivity.java index 2e900371..8d214dd7 100644 --- a/app/src/main/java/com/android/onyx/demo/RefreshModeDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/RefreshModeDemoActivity.java @@ -5,33 +5,32 @@ import android.support.v7.app.AppCompatActivity; import android.widget.RadioGroup; +import androidx.databinding.DataBindingUtil; + import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityRefreshModeDemoBinding; import com.onyx.android.sdk.api.device.epd.UpdateOption; import com.onyx.android.sdk.device.Device; -import butterknife.Bind; -import butterknife.ButterKnife; public class RefreshModeDemoActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener { private static final String TAG = RefreshModeDemoActivity.class.getSimpleName(); - @Bind(R.id.rg_refresh_mode) - public RadioGroup rgRefreshmode; + private ActivityRefreshModeDemoBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_refresh_mode_demo); - ButterKnife.bind(this); + binding = DataBindingUtil.setContentView(this, R.layout.activity_refresh_mode_demo); initData(); - rgRefreshmode.setOnCheckedChangeListener(this); + binding.rgRefreshMode.setOnCheckedChangeListener(this); } private void initData() { UpdateOption updateOption = Device.currentDevice().getSystemRefreshMode(); - rgRefreshmode.check(getRadioButtonIdByUpdateOption(updateOption)); + binding.rgRefreshMode.check(getRadioButtonIdByUpdateOption(updateOption)); } @Override diff --git a/app/src/main/java/com/android/onyx/demo/ScreensaverActivity.java b/app/src/main/java/com/android/onyx/demo/ScreensaverActivity.java index a0824288..e7b1c279 100644 --- a/app/src/main/java/com/android/onyx/demo/ScreensaverActivity.java +++ b/app/src/main/java/com/android/onyx/demo/ScreensaverActivity.java @@ -10,28 +10,29 @@ import android.support.v7.app.AppCompatActivity; import android.util.DisplayMetrics; import android.view.Display; +import android.view.View; import android.view.WindowManager; -import android.widget.EditText; + import android.widget.Toast; +import androidx.databinding.DataBindingUtil; + import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityScreenSaverBinding; import com.onyx.android.sdk.utils.BitmapUtils; import java.io.File; -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnClick; public class ScreensaverActivity extends AppCompatActivity { - @Bind(R.id.et_image) - EditText etImage; + + private ActivityScreenSaverBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_screen_saver); - ButterKnife.bind(this); + binding = DataBindingUtil.setContentView(this, R.layout.activity_screen_saver); + binding.setActivityScreenSaver(this); } /** @@ -40,23 +41,23 @@ protected void onCreate(Bundle savedInstanceState) { * 2. file names format "standby-{num}.png", num starts from 1
* 3. send broadcast with action "update_standby_pic"
* PS.pic's width and height better matches the device's height and width,
- * for example device's size is 2200x1650, pic's size should be 1650x2200, with upside towards left,
- * and pic's file format should be png. + * for example device's size is 2200x1650, pic's size should be 1650x2200, with upside towards left,
+ * and pic's file format should be png. */ - @OnClick(R.id.btn_set) - public void setScreensaver() { - String filePath = etImage.getText().toString(); - if ( "".equals(filePath) ) { - Toast.makeText(this,R.string.enter_pic_path, Toast.LENGTH_SHORT).show(); + + public void setScreensaver(View view) { + String filePath = binding.etImage.getText().toString(); + if ("".equals(filePath)) { + Toast.makeText(this, R.string.enter_pic_path, Toast.LENGTH_SHORT).show(); return; } File f = new File(filePath); - if ( !f.exists() ) { - Toast.makeText(this,R.string.invalid_path, Toast.LENGTH_SHORT).show(); + if (!f.exists()) { + Toast.makeText(this, R.string.invalid_path, Toast.LENGTH_SHORT).show(); return; } - String path = etImage.getText().toString(); + String path = binding.etImage.getText().toString(); Bitmap temp = BitmapFactory.decodeFile(path); if (temp.getHeight() > temp.getWidth()) { temp = BitmapUtils.rotateBmp(temp, 270); @@ -86,7 +87,7 @@ public void setScreensaver() { } public static Point getScreenResolution(final Context context) { - WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); + WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display d = w.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); d.getMetrics(metrics); diff --git a/app/src/main/java/com/android/onyx/demo/WebViewOptimizeActivity.java b/app/src/main/java/com/android/onyx/demo/WebViewOptimizeActivity.java index 8463f7f6..fff1529e 100644 --- a/app/src/main/java/com/android/onyx/demo/WebViewOptimizeActivity.java +++ b/app/src/main/java/com/android/onyx/demo/WebViewOptimizeActivity.java @@ -2,14 +2,16 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.view.View; import android.webkit.WebView; import android.webkit.WebViewClient; +import androidx.databinding.DataBindingUtil; + import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityWebviewOptimizeBinding; import com.onyx.android.sdk.api.device.epd.EpdController; -import butterknife.ButterKnife; -import butterknife.OnClick; public class WebViewOptimizeActivity extends AppCompatActivity { @@ -17,19 +19,20 @@ public class WebViewOptimizeActivity extends AppCompatActivity { private boolean toggled = true; + private ActivityWebviewOptimizeBinding binding; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_webview_optimize); - ButterKnife.bind(this); + binding = DataBindingUtil.setContentView(this, R.layout.activity_webview_optimize); + binding.setActivityWebview(this); - webView = findViewById(R.id.web_view); + webView = binding.webView; webView.setWebViewClient(new WebViewClient()); webView.loadUrl("https://www.google.com"); } - - @OnClick(R.id.button_toggle_optimize) - public void toggleOptimize() { + + public void toggleOptimize(View view) { toggled = !toggled; EpdController.setWebViewContrastOptimize(webView, toggled); } diff --git a/app/src/main/java/com/android/onyx/demo/scribble/ScribbleDemoActivity.java b/app/src/main/java/com/android/onyx/demo/scribble/ScribbleDemoActivity.java index 6b0e4631..76930e84 100644 --- a/app/src/main/java/com/android/onyx/demo/scribble/ScribbleDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/scribble/ScribbleDemoActivity.java @@ -4,50 +4,49 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; +import android.view.View; + +import androidx.databinding.DataBindingUtil; import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivitySribbleDemoBinding; -import butterknife.ButterKnife; -import butterknife.OnClick; /** * Created by seeksky on 2018/4/26. */ public class ScribbleDemoActivity extends AppCompatActivity { + private ActivitySribbleDemoBinding binding; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_sribble_demo); - ButterKnife.bind(this); + binding = DataBindingUtil.setContentView(this, R.layout.activity_sribble_demo); + binding.setActivitySribble(this); } - @OnClick(R.id.button_scribble_touch_helper) - public void button_scribble_touch_helper() { + + public void button_scribble_touch_helper(View view) { go(ScribbleTouchHelperDemoActivity.class); } - @OnClick(R.id.button_surfaceview_stylus_scribble) - public void button_surfaceview_stylus_scribble() { + public void button_surfaceview_stylus_scribble(View view) { go(ScribbleTouchHelperDemoActivity.class); } - @OnClick(R.id.button_webview_stylus_scribble) - public void button_webview_stylus_scribble() { + public void button_webview_stylus_scribble(View view) { go(ScribbleWebViewDemoActivity.class); } - @OnClick(R.id.button_move_erase_scribble) - public void button_move_erase_scribble() { + public void button_move_erase_scribble(View view) { go(ScribbleMoveEraserDemoActivity.class); } - @OnClick(R.id.button_multiple_scribble) - public void button_multiple_scribble() { + public void button_multiple_scribble(View view) { go(ScribbleMultipleScribbleViewActivity.class); } - @OnClick(R.id.button_pen_up_refresh) - public void button_pen_up_refresh() { + public void button_pen_up_refresh(View view) { go(ScribblePenUpRefreshDemoActivity.class); } diff --git a/app/src/main/java/com/android/onyx/demo/scribble/ScribbleMoveEraserDemoActivity.java b/app/src/main/java/com/android/onyx/demo/scribble/ScribbleMoveEraserDemoActivity.java index 625cdcda..ac103a37 100644 --- a/app/src/main/java/com/android/onyx/demo/scribble/ScribbleMoveEraserDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/scribble/ScribbleMoveEraserDemoActivity.java @@ -13,10 +13,14 @@ import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.SurfaceHolder; -import android.view.SurfaceView; -import android.widget.Button; + +import android.view.View; + + +import androidx.databinding.DataBindingUtil; import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityScribbleMoveEraseStylusDemoBinding; import com.onyx.android.sdk.api.device.epd.EpdController; import com.onyx.android.sdk.pen.RawInputCallback; import com.onyx.android.sdk.pen.TouchHelper; @@ -27,21 +31,12 @@ import java.util.Iterator; import java.util.List; -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnClick; public class ScribbleMoveEraserDemoActivity extends AppCompatActivity { private static final String TAG = ScribbleMoveEraserDemoActivity.class.getSimpleName(); - @Bind(R.id.button_pen) - Button buttonPen; - @Bind(R.id.button_eraser) - Button buttonEraser; - @Bind(R.id.surfaceview) - SurfaceView surfaceView; - + private ActivityScribbleMoveEraseStylusDemoBinding binding; private TouchHelper touchHelper; private List points = new ArrayList<>(); @@ -58,10 +53,8 @@ public class ScribbleMoveEraserDemoActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_scribble_move_erase_stylus_demo); - - ButterKnife.bind(this); - + binding = DataBindingUtil.setContentView(this, R.layout.activity_scribble_move_erase_stylus_demo); + binding.setActivityScribbleMoveErase(this); initSurfaceView(); } @@ -84,16 +77,16 @@ protected void onDestroy() { } private void initSurfaceView() { - touchHelper = TouchHelper.create(surfaceView, getRawInputCallback()); + touchHelper = TouchHelper.create(binding.surfaceview, getRawInputCallback()); if (surfaceCallback == null) { surfaceCallback = new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder holder) { Rect limit = new Rect(); - surfaceView.getLocalVisibleRect(limit); + binding.surfaceview.getLocalVisibleRect(limit); bkGroundBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.scribble_back_ground_grid); - renderBitmap = Bitmap.createBitmap(surfaceView.getWidth(), - surfaceView.getHeight(), + renderBitmap = Bitmap.createBitmap(binding.surfaceview.getWidth(), + binding.surfaceview.getHeight(), Bitmap.Config.ARGB_8888); renderBitmap.eraseColor(Color.TRANSPARENT); canvas = new Canvas(renderBitmap); @@ -114,7 +107,7 @@ public void surfaceDestroyed(SurfaceHolder holder) { } }; } - surfaceView.getHolder().addCallback(surfaceCallback); + binding.surfaceview.getHolder().addCallback(surfaceCallback); } public RawInputCallback getRawInputCallback() { @@ -190,14 +183,11 @@ private void initPaint(Paint paint) { paint.setStrokeMiter(4.0f); } - - @OnClick(R.id.button_pen) - public void onPenClick(){ + public void onPenClick(View view) { touchHelper.setRawDrawingEnabled(true); } - @OnClick(R.id.button_eraser) - public void onEraserClick(){ + public void onEraserClick(View view) { touchHelper.setRawDrawingEnabled(false); renderBitmap.eraseColor(Color.TRANSPARENT); drawBitmap(); @@ -237,22 +227,22 @@ private void eraseBitmap(Path path) { } private void drawBitmap() { - if (surfaceView.getHolder() == null) { + if (binding.surfaceview.getHolder() == null) { return; } - Canvas canvas = surfaceView.getHolder().lockCanvas(); + Canvas canvas = binding.surfaceview.getHolder().lockCanvas(); if (canvas == null) { return; } - EpdController.enablePost(surfaceView, 1); + EpdController.enablePost(binding.surfaceview, 1); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); - Rect rect = new Rect(0, 0, surfaceView.getWidth(), surfaceView.getHeight()); + Rect rect = new Rect(0, 0, binding.surfaceview.getWidth(), binding.surfaceview.getHeight()); canvas.drawRect(rect, paint); canvas.drawBitmap(bkGroundBitmap, null, rect, paint); canvas.drawBitmap(renderBitmap, 0, 0, paint); - surfaceView.getHolder().unlockCanvasAndPost(canvas); + binding.surfaceview.getHolder().unlockCanvasAndPost(canvas); } public Path createPath(final TouchPointList pointList) { diff --git a/app/src/main/java/com/android/onyx/demo/scribble/ScribbleMultipleScribbleViewActivity.java b/app/src/main/java/com/android/onyx/demo/scribble/ScribbleMultipleScribbleViewActivity.java index 9946551a..2ac90fe1 100644 --- a/app/src/main/java/com/android/onyx/demo/scribble/ScribbleMultipleScribbleViewActivity.java +++ b/app/src/main/java/com/android/onyx/demo/scribble/ScribbleMultipleScribbleViewActivity.java @@ -8,9 +8,11 @@ import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; -import android.widget.Button; + +import androidx.databinding.DataBindingUtil; import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityScribbleMultipleScrubbleViewDemoBinding; import com.onyx.android.sdk.pen.RawInputCallback; import com.onyx.android.sdk.pen.TouchHelper; import com.onyx.android.sdk.data.note.TouchPoint; @@ -19,24 +21,12 @@ import java.util.ArrayList; import java.util.List; -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnClick; public class ScribbleMultipleScribbleViewActivity extends AppCompatActivity { private static final String TAG = ScribbleMultipleScribbleViewActivity.class.getSimpleName(); - @Bind(R.id.button_pen) - Button buttonPen; - @Bind(R.id.button_eraser) - Button buttonEraser; - @Bind(R.id.content) - View content; - @Bind(R.id.surfaceview1) - SurfaceView surfaceView1; - @Bind(R.id.surfaceview2) - SurfaceView surfaceView2; + private ActivityScribbleMultipleScrubbleViewDemoBinding binding; private TouchHelper touchHelper; @@ -46,12 +36,12 @@ public class ScribbleMultipleScribbleViewActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_scribble_multiple_scrubble_view_demo); + binding = DataBindingUtil.setContentView(this, R.layout.activity_scribble_multiple_scrubble_view_demo); + binding.setActivityScribbleMultiple(this); - ButterKnife.bind(this); touchHelper = TouchHelper.create(getWindow().getDecorView().getRootView(), getRawInputCallback()); - initSurfaceView(surfaceView1); - initSurfaceView(surfaceView2); + initSurfaceView(binding.surfaceview1); + initSurfaceView(binding.surfaceview2); } @Override @@ -145,29 +135,24 @@ public void onRawErasingTouchPointListReceived(TouchPointList touchPointList) { return rawInputCallback; } - - @OnClick(R.id.button_pen) - public void onPenClick(){ + public void onPenClick(View view) { touchHelper.setRawDrawingEnabled(true); } - @OnClick(R.id.button_eraser) - public void onEraserClick(){ + public void onEraserClick(View view) { touchHelper.setRawDrawingEnabled(false); cleanAllSurfaceView(); touchHelper.setRawDrawingEnabled(true); } - @OnClick(R.id.button_single_region_mode) - public void onSingleRegionModeClick() { + public void onSingleRegionModeClick(View view) { touchHelper.setRawDrawingEnabled(false); cleanAllSurfaceView(); touchHelper.setSingleRegionMode(); touchHelper.setRawDrawingEnabled(true); } - @OnClick(R.id.button_multi_region_mode) - public void onMultiRegionModeClick() { + public void onMultiRegionModeClick(View view) { touchHelper.setRawDrawingEnabled(false); cleanAllSurfaceView(); touchHelper.setMultiRegionMode(); @@ -175,8 +160,8 @@ public void onMultiRegionModeClick() { } private void cleanAllSurfaceView() { - cleanSurfaceView(surfaceView1); - cleanSurfaceView(surfaceView2); + cleanSurfaceView(binding.surfaceview1); + cleanSurfaceView(binding.surfaceview2); } private void cleanSurfaceView(SurfaceView surfaceView) { diff --git a/app/src/main/java/com/android/onyx/demo/scribble/ScribblePenUpRefreshDemoActivity.java b/app/src/main/java/com/android/onyx/demo/scribble/ScribblePenUpRefreshDemoActivity.java index 5673a72d..9f7493dd 100644 --- a/app/src/main/java/com/android/onyx/demo/scribble/ScribblePenUpRefreshDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/scribble/ScribblePenUpRefreshDemoActivity.java @@ -18,16 +18,18 @@ import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; -import android.widget.Button; -import android.widget.CheckBox; + import android.widget.CompoundButton; import android.widget.RadioButton; -import android.widget.RadioGroup; + import android.widget.SeekBar; -import android.widget.TextView; + + +import androidx.databinding.DataBindingUtil; import com.onyx.android.demo.R; import com.android.onyx.demo.scribble.request.PartialRefreshRequest; +import com.onyx.android.demo.databinding.ActivityPenUpRefreshDemoBinding; import com.onyx.android.sdk.api.device.epd.EpdController; import com.onyx.android.sdk.data.PenConstant; import com.onyx.android.sdk.pen.NeoFountainPen; @@ -42,31 +44,13 @@ import java.util.ArrayList; import java.util.List; -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnClick; public class ScribblePenUpRefreshDemoActivity extends AppCompatActivity { private static final String TAG = ScribblePenUpRefreshDemoActivity.class.getSimpleName(); private final float STROKE_WIDTH = 3.0f; - @Bind(R.id.button_pen) - Button buttonPen; - @Bind(R.id.content) - View content; - @Bind(R.id.surfaceview1) - SurfaceView surfaceView; - @Bind(R.id.enable_pen_up_refresh) - CheckBox cbPenUpRefreshEnable; - @Bind(R.id.pen_up_time) - TextView penUpTime; - @Bind(R.id.seekBar) - SeekBar penUpTimeSeekBar; - @Bind(R.id.rg_stroke_style) - RadioGroup rgStrokeStyle; - @Bind(R.id.button_test_view_update) - Button buttonTestViewUpdate; + private ActivityPenUpRefreshDemoBinding binding; private TouchHelper touchHelper; private RawInputCallback rawInputCallback; @@ -78,10 +62,9 @@ public class ScribblePenUpRefreshDemoActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_pen_up_refresh_demo); - - ButterKnife.bind(this); - initSurfaceView(surfaceView); + binding = DataBindingUtil.setContentView(this, R.layout.activity_pen_up_refresh_demo); + binding.setActivityPenUpRefresh(this); + initSurfaceView(binding.surfaceview1); initPaint(); } @@ -106,29 +89,25 @@ protected void onDestroy() { super.onDestroy(); } - @OnClick(R.id.button_pen) public void onPenClick() { touchHelper.setRawDrawingEnabled(true); } - @OnClick(R.id.button_clear) public void onClearClick() { touchHelper.setRawDrawingEnabled(false); bitmapRecycle(); - cleanSurfaceView(surfaceView); + cleanSurfaceView(binding.surfaceview1); touchHelper.setRawDrawingEnabled(true); } - @OnClick(R.id.button_test_view_update) - public void onTestViewUpdateClick() { - buttonTestViewUpdate.setEnabled(false); + public void onTestViewUpdateClick(View view) { + binding.buttonTestViewUpdate.setEnabled(false); touchHelper.setRawDrawingEnabled(false); showTestDialog(); } - @OnClick({R.id.rb_brush, R.id.rb_pencil}) - public void onRadioButtonClicked(RadioButton radioButton) { - boolean checked = radioButton.isChecked(); + public void onRadioButtonClicked(View radioButton) { + boolean checked = ((RadioButton) radioButton).isChecked(); Log.d(TAG, radioButton.toString()); switch (radioButton.getId()) { case R.id.rb_brush: @@ -194,7 +173,7 @@ public void onPenUpRefresh(RectF refreshRect) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return; } - getRxManager().enqueue(new PartialRefreshRequest(ScribblePenUpRefreshDemoActivity.this, surfaceView, refreshRect) + getRxManager().enqueue(new PartialRefreshRequest(ScribblePenUpRefreshDemoActivity.this, binding.surfaceview1, refreshRect) .setBitmap(bitmap), new RxCallback() { @Override @@ -216,11 +195,11 @@ private void initPaint() { private void drawScribbleToBitmap(List list) { if (bitmap == null) { - bitmap = Bitmap.createBitmap(surfaceView.getWidth(), surfaceView.getHeight(), Bitmap.Config.ARGB_8888); + bitmap = Bitmap.createBitmap(binding.surfaceview1.getWidth(), binding.surfaceview1.getHeight(), Bitmap.Config.ARGB_8888); canvas = new Canvas(bitmap); } - switch (rgStrokeStyle.getCheckedRadioButtonId()) { + switch (binding.rgStrokeStyle.getCheckedRadioButtonId()) { case R.id.rb_brush: float maxPressure = EpdController.getMaxTouchPressure(); NeoFountainPen.drawStroke(canvas, paint, list, NumberUtils.FLOAT_ONE, STROKE_WIDTH, maxPressure, false); @@ -267,17 +246,18 @@ public void surfaceDestroyed(SurfaceHolder holder) { } private void initPenUpRefreshConfig() { - cbPenUpRefreshEnable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + binding.enablePenUpRefresh.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { touchHelper.setRawDrawingEnabled(false); bitmapRecycle(); - cleanSurfaceView(surfaceView); + cleanSurfaceView(binding.surfaceview1); touchHelper.setPenUpRefreshEnabled(isChecked); touchHelper.setRawDrawingEnabled(true); } }); - penUpTimeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + + binding.seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { touchHelper.setRawDrawingEnabled(false); @@ -295,14 +275,14 @@ public void onStartTrackingTouch(SeekBar seekBar) { public void onStopTrackingTouch(SeekBar seekBar) { } }); - cbPenUpRefreshEnable.setChecked(true); - penUpTimeSeekBar.setMax(PenConstant.MAX_PEN_UP_REFRESH_TIME_MS - PenConstant.MIN_PEN_UP_REFRESH_TIME_MS); + binding.enablePenUpRefresh.setChecked(true); + binding.seekBar.setMax(PenConstant.MAX_PEN_UP_REFRESH_TIME_MS - PenConstant.MIN_PEN_UP_REFRESH_TIME_MS); updateSeekBarValue(PenConstant.DEFAULT_PEN_UP_REFRESH_TIME_MS); } private void updateSeekBarValue(int time) { - penUpTime.setText(String.valueOf(time)); - penUpTimeSeekBar.setProgress(time - PenConstant.MIN_PEN_UP_REFRESH_TIME_MS); + binding.penUpTime.setText(String.valueOf(time)); + binding.seekBar.setProgress(time - PenConstant.MIN_PEN_UP_REFRESH_TIME_MS); touchHelper.setPenUpRefreshTimeMs(time); } @@ -347,7 +327,7 @@ public void onClick(DialogInterface dialog, int which) { dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { - buttonTestViewUpdate.setEnabled(true); + binding.buttonTestViewUpdate.setEnabled(true); touchHelper.setRawDrawingEnabled(true); } }); diff --git a/app/src/main/java/com/android/onyx/demo/scribble/ScribbleTouchHelperDemoActivity.java b/app/src/main/java/com/android/onyx/demo/scribble/ScribbleTouchHelperDemoActivity.java index 4cacb349..582aae2e 100644 --- a/app/src/main/java/com/android/onyx/demo/scribble/ScribbleTouchHelperDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/scribble/ScribbleTouchHelperDemoActivity.java @@ -14,14 +14,16 @@ import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; -import android.widget.Button; -import android.widget.CheckBox; + import android.widget.RadioButton; +import androidx.databinding.DataBindingUtil; + import com.onyx.android.demo.R; import com.android.onyx.demo.broadcast.GlobalDeviceReceiver; import com.android.onyx.demo.scribble.request.RendererToScreenRequest; import com.android.onyx.demo.utils.TouchUtils; +import com.onyx.android.demo.databinding.ActivityPenStylusTouchHelperDemoBinding; import com.onyx.android.sdk.api.device.epd.EpdController; import com.onyx.android.sdk.pen.NeoFountainPen; import com.onyx.android.sdk.pen.RawInputCallback; @@ -34,29 +36,16 @@ import java.util.ArrayList; import java.util.List; -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnCheckedChanged; -import butterknife.OnClick; public class ScribbleTouchHelperDemoActivity extends AppCompatActivity { private static final String TAG = ScribbleTouchHelperDemoActivity.class.getSimpleName(); - /** skip point count*/ + /** + * skip point count + */ private static final int INTERVAL = 10; - @Bind(R.id.button_pen) - Button buttonPen; - @Bind(R.id.button_eraser) - Button buttonEraser; - @Bind(R.id.surfaceview) - SurfaceView surfaceView; - @Bind(R.id.cb_render) - CheckBox cbRender; - @Bind(R.id.rb_brush) - RadioButton rbBrush; - @Bind(R.id.rb_pencil) - RadioButton rbPencil; + private ActivityPenStylusTouchHelperDemoBinding binding; private GlobalDeviceReceiver deviceReceiver = new GlobalDeviceReceiver(); private RxManager rxManager; @@ -75,10 +64,10 @@ public class ScribbleTouchHelperDemoActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_pen_stylus_touch_helper_demo); + binding = DataBindingUtil.setContentView(this, R.layout.activity_pen_stylus_touch_helper_demo); deviceReceiver.enable(this, true); + binding.setActivityPenStylusTouchHelper(this); - ButterKnife.bind(this); initPaint(); initSurfaceView(); initReceiver(); @@ -99,7 +88,7 @@ protected void onPause() { @Override protected void onDestroy() { touchHelper.closeRawDrawing(); - if (bitmap !=null) { + if (bitmap != null) { bitmap.recycle(); bitmap = null; } @@ -118,7 +107,7 @@ public void renderToScreen(SurfaceView surfaceView, Bitmap bitmap) { getRxManager().enqueue(new RendererToScreenRequest(surfaceView, bitmap), null); } - private void initPaint(){ + private void initPaint() { paint.setAntiAlias(true); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.BLACK); @@ -126,34 +115,34 @@ private void initPaint(){ } private void initSurfaceView() { - touchHelper = TouchHelper.create(surfaceView, callback); + touchHelper = TouchHelper.create(binding.surfaceview, callback); - surfaceView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + binding.surfaceview.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - if (cleanSurfaceView()){ - surfaceView.removeOnLayoutChangeListener(this); + if (cleanSurfaceView()) { + binding.surfaceview.removeOnLayoutChangeListener(this); } List exclude = new ArrayList<>(); - exclude.add(getRelativeRect(surfaceView, buttonEraser)); - exclude.add(getRelativeRect(surfaceView, buttonPen)); - exclude.add(getRelativeRect(surfaceView, cbRender)); - exclude.add(getRelativeRect(surfaceView, rbBrush)); - exclude.add(getRelativeRect(surfaceView, rbPencil)); + exclude.add(getRelativeRect(binding.surfaceview, binding.buttonEraser)); + exclude.add(getRelativeRect(binding.surfaceview, binding.buttonPen)); + exclude.add(getRelativeRect(binding.surfaceview, binding.cbRender)); + exclude.add(getRelativeRect(binding.surfaceview, binding.rbBrush)); + exclude.add(getRelativeRect(binding.surfaceview, binding.rbPencil)); Rect limit = new Rect(); - surfaceView.getLocalVisibleRect(limit); + binding.surfaceview.getLocalVisibleRect(limit); touchHelper.setStrokeWidth(STROKE_WIDTH) - .setLimitRect(limit, exclude) - .openRawDrawing(); + .setLimitRect(limit, exclude) + .openRawDrawing(); touchHelper.setStrokeStyle(TouchHelper.STROKE_STYLE_BRUSH); - rbBrush.setChecked(true); - surfaceView.addOnLayoutChangeListener(this); + binding.rbBrush.setChecked(true); + binding.surfaceview.addOnLayoutChangeListener(this); } }); - surfaceView.setOnTouchListener(new View.OnTouchListener() { + binding.surfaceview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { Log.d(TAG, "surfaceView.setOnTouchListener - onTouch::action - " + event.getAction()); @@ -176,7 +165,7 @@ public void surfaceDestroyed(SurfaceHolder holder) { holder.removeCallback(this); } }; - surfaceView.getHolder().addCallback(surfaceCallback); + binding.surfaceview.getHolder().addCallback(surfaceCallback); } private void initReceiver() { @@ -184,46 +173,42 @@ private void initReceiver() { @Override public void onNotificationPanelChanged(boolean open) { touchHelper.setRawDrawingEnabled(!open); - renderToScreen(surfaceView, bitmap); + renderToScreen(binding.surfaceview, bitmap); } }).setSystemScreenOnListener(new GlobalDeviceReceiver.SystemScreenOnListener() { @Override public void onScreenOn() { - renderToScreen(surfaceView, bitmap); + renderToScreen(binding.surfaceview, bitmap); } }); } - @OnClick(R.id.button_pen) public void onPenClick() { touchHelper.setRawDrawingEnabled(true); onRenderEnableClick(); } - @OnClick(R.id.button_eraser) public void onEraserClick() { touchHelper.setRawDrawingEnabled(false); - if (bitmap !=null) { + if (bitmap != null) { bitmap.recycle(); bitmap = null; } cleanSurfaceView(); } - @OnCheckedChanged(R.id.cb_render) public void onRenderEnableClick() { - touchHelper.setRawDrawingRenderEnabled(cbRender.isChecked()); - if (bitmap !=null) { + touchHelper.setRawDrawingRenderEnabled(binding.cbRender.isChecked()); + if (bitmap != null) { bitmap.recycle(); bitmap = null; } - Log.d(TAG,"onRenderEnableClick setRawDrawingRenderEnabled = " + cbRender.isChecked()); + Log.d(TAG, "onRenderEnableClick setRawDrawingRenderEnabled = " + binding.cbRender.isChecked()); } - @OnClick({R.id.rb_brush, R.id.rb_pencil}) - public void onRadioButtonClicked(RadioButton radioButton) { + public void onRadioButtonClicked(View radioButton) { - boolean checked = radioButton.isChecked(); + boolean checked = ((RadioButton) radioButton).isChecked(); Log.d(TAG, radioButton.toString()); switch (radioButton.getId()) { case R.id.rb_brush: @@ -245,8 +230,8 @@ public void onRadioButtonClicked(RadioButton radioButton) { } public Rect getRelativeRect(final View parentView, final View childView) { - int [] parent = new int[2]; - int [] child = new int[2]; + int[] parent = new int[2]; + int[] child = new int[2]; parentView.getLocationOnScreen(parent); childView.getLocationOnScreen(child); Rect rect = new Rect(); @@ -256,33 +241,33 @@ public Rect getRelativeRect(final View parentView, final View childView) { } private boolean cleanSurfaceView() { - if (surfaceView.getHolder() == null) { + if (binding.surfaceview.getHolder() == null) { return false; } - Canvas canvas = surfaceView.getHolder().lockCanvas(); + Canvas canvas = binding.surfaceview.getHolder().lockCanvas(); if (canvas == null) { return false; } canvas.drawColor(Color.WHITE); - surfaceView.getHolder().unlockCanvasAndPost(canvas); + binding.surfaceview.getHolder().unlockCanvasAndPost(canvas); return true; } - private void drawRect(TouchPoint endPoint){ - Canvas canvas = surfaceView.getHolder().lockCanvas(); - if (canvas == null ) { + private void drawRect(TouchPoint endPoint) { + Canvas canvas = binding.surfaceview.getHolder().lockCanvas(); + if (canvas == null) { return; } if (startPoint == null || endPoint == null) { - surfaceView.getHolder().unlockCanvasAndPost(canvas); + binding.surfaceview.getHolder().unlockCanvasAndPost(canvas); return; } canvas.drawColor(Color.WHITE); canvas.drawRect(startPoint.getX(), startPoint.getY(), endPoint.getX(), endPoint.getY(), paint); - Log.d(TAG,"drawRect "); - surfaceView.getHolder().unlockCanvasAndPost(canvas); + Log.d(TAG, "drawRect "); + binding.surfaceview.getHolder().unlockCanvasAndPost(canvas); } private RawInputCallback callback = new RawInputCallback() { @@ -291,7 +276,7 @@ private void drawRect(TouchPoint endPoint){ public void onBeginRawDrawing(boolean b, TouchPoint touchPoint) { Log.d(TAG, "onBeginRawDrawing"); startPoint = touchPoint; - Log.d(TAG,touchPoint.getX() +", " +touchPoint.getY()); + Log.d(TAG, touchPoint.getX() + ", " + touchPoint.getY()); countRec = 0; TouchUtils.disableFingerTouch(getApplicationContext()); } @@ -299,20 +284,20 @@ public void onBeginRawDrawing(boolean b, TouchPoint touchPoint) { @Override public void onEndRawDrawing(boolean b, TouchPoint touchPoint) { Log.d(TAG, "onEndRawDrawing###"); - if (!cbRender.isChecked()){ + if (!binding.cbRender.isChecked()) { drawRect(touchPoint); } - Log.d(TAG,touchPoint.getX() +", " +touchPoint.getY()); + Log.d(TAG, touchPoint.getX() + ", " + touchPoint.getY()); TouchUtils.enableFingerTouch(getApplicationContext()); } @Override public void onRawDrawingTouchPointMoveReceived(TouchPoint touchPoint) { Log.d(TAG, "onRawDrawingTouchPointMoveReceived"); - Log.d(TAG,touchPoint.getX() +", " +touchPoint.getY()); + Log.d(TAG, touchPoint.getX() + ", " + touchPoint.getY()); countRec++; countRec = countRec % INTERVAL; - Log.d(TAG,"countRec = " + countRec); + Log.d(TAG, "countRec = " + countRec); } @Override @@ -343,20 +328,20 @@ public void onRawErasingTouchPointListReceived(TouchPointList touchPointList) { }; private void drawScribbleToBitmap(List list) { - if (!cbRender.isChecked()) { + if (!binding.cbRender.isChecked()) { return; } if (bitmap == null) { - bitmap = Bitmap.createBitmap(surfaceView.getWidth(), surfaceView.getHeight(), Bitmap.Config.ARGB_8888); + bitmap = Bitmap.createBitmap(binding.surfaceview.getWidth(), binding.surfaceview.getHeight(), Bitmap.Config.ARGB_8888); canvas = new Canvas(bitmap); } - if (rbBrush.isChecked()) { + if (binding.rbBrush.isChecked()) { float maxPressure = EpdController.getMaxTouchPressure(); NeoFountainPen.drawStroke(canvas, paint, list, NumberUtils.FLOAT_ONE, STROKE_WIDTH, maxPressure, false); } - if (rbPencil.isChecked()) { + if (binding.rbPencil.isChecked()) { Path path = new Path(); PointF prePoint = new PointF(list.get(0).x, list.get(0).y); path.moveTo(prePoint.x, prePoint.y); @@ -370,23 +355,23 @@ private void drawScribbleToBitmap(List list) { } private void drawBitmapToSurface() { - if (!cbRender.isChecked()) { + if (!binding.cbRender.isChecked()) { return; } if (bitmap == null) { return; } - Canvas lockCanvas= surfaceView.getHolder().lockCanvas(); + Canvas lockCanvas = binding.surfaceview.getHolder().lockCanvas(); if (lockCanvas == null) { return; } lockCanvas.drawColor(Color.WHITE); lockCanvas.drawBitmap(bitmap, 0f, 0f, paint); - surfaceView.getHolder().unlockCanvasAndPost(lockCanvas); + binding.surfaceview.getHolder().unlockCanvasAndPost(lockCanvas); // refresh ui touchHelper.setRawDrawingEnabled(false); touchHelper.setRawDrawingEnabled(true); - if (!cbRender.isChecked()) { + if (!binding.cbRender.isChecked()) { touchHelper.setRawDrawingRenderEnabled(false); } } diff --git a/app/src/main/java/com/android/onyx/demo/scribble/ScribbleWebViewDemoActivity.java b/app/src/main/java/com/android/onyx/demo/scribble/ScribbleWebViewDemoActivity.java index 5536282f..205149f8 100644 --- a/app/src/main/java/com/android/onyx/demo/scribble/ScribbleWebViewDemoActivity.java +++ b/app/src/main/java/com/android/onyx/demo/scribble/ScribbleWebViewDemoActivity.java @@ -12,11 +12,14 @@ import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; -import android.widget.Button; + import android.widget.Toast; +import androidx.databinding.DataBindingUtil; + import com.android.onyx.demo.utils.TouchUtils; import com.onyx.android.demo.R; +import com.onyx.android.demo.databinding.ActivityScribbleWebviewStylusDemoBinding; import com.onyx.android.sdk.api.device.epd.EpdController; import com.onyx.android.sdk.pen.RawInputCallback; import com.onyx.android.sdk.pen.TouchHelper; @@ -28,8 +31,6 @@ import java.util.ArrayList; import java.util.List; -import butterknife.Bind; -import butterknife.ButterKnife; /** * Created by seeksky on 2018/4/26. @@ -38,22 +39,17 @@ public class ScribbleWebViewDemoActivity extends AppCompatActivity implements View.OnClickListener { private final String TAG = getClass().getSimpleName(); - @Bind(R.id.button_pen) - Button buttonPen; - @Bind(R.id.button_eraser) - Button buttonEraser; - @Bind(R.id.surfaceview) - WebView webView; private TouchHelper touchHelper; + private ActivityScribbleWebviewStylusDemoBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_scribble_webview_stylus_demo); + binding = DataBindingUtil.setContentView(this, R.layout.activity_scribble_webview_stylus_demo); - ButterKnife.bind(this); - buttonPen.setOnClickListener(this); - buttonEraser.setOnClickListener(this); + + binding.buttonPen.setOnClickListener(this); + binding.buttonEraser.setOnClickListener(this); initWebView(); } @@ -81,7 +77,7 @@ private class MyWebViewClient extends WebViewClient { public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); String js = "android.btns(getBtns());"; - webView.loadUrl("javascript:" + js); + binding.surfaceview.loadUrl("javascript:" + js); } } @@ -106,7 +102,7 @@ private String readHtmlFile() { try { int count; byte[] bytes = new byte[32768]; - while ( (count = in.read(bytes,0, 32768)) > 0) { + while ((count = in.read(bytes, 0, 32768)) > 0) { builder.append(new String(bytes, 0, count)); } @@ -118,19 +114,19 @@ private String readHtmlFile() { } private void initWebView() { - EpdController.setWebViewContrastOptimize(webView, false); - touchHelper = TouchHelper.create(webView, callback); - webView.setWebViewClient(new MyWebViewClient()); - webView.addJavascriptInterface(new WebJsInterface(this), "android"); - webView.setWebChromeClient(new WebChromeClient() { + EpdController.setWebViewContrastOptimize(binding.surfaceview, false); + touchHelper = TouchHelper.create(binding.surfaceview, callback); + binding.surfaceview.setWebViewClient(new MyWebViewClient()); + binding.surfaceview.addJavascriptInterface(new WebJsInterface(this), "android"); + binding.surfaceview.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } }); - webView.getSettings().setJavaScriptEnabled(true); - webView.loadData(readHtmlFile(), "text/html", "utf-8"); - webView.post(new Runnable() { + binding.surfaceview.getSettings().setJavaScriptEnabled(true); + binding.surfaceview.loadData(readHtmlFile(), "text/html", "utf-8"); + binding.surfaceview.post(new Runnable() { @Override public void run() { initTouchHelper(); @@ -140,19 +136,19 @@ public void run() { private void initTouchHelper() { List exclude = new ArrayList<>(); - exclude.add(getRelativeRect(webView, buttonEraser)); - exclude.add(getRelativeRect(webView, buttonPen)); + exclude.add(getRelativeRect(binding.surfaceview, binding.buttonEraser)); + exclude.add(getRelativeRect(binding.surfaceview, binding.buttonPen)); Rect limit = new Rect(); - webView.getLocalVisibleRect(limit); + binding.surfaceview.getLocalVisibleRect(limit); touchHelper.setStrokeWidth(3.0f) - .setLimitRect(limit, exclude) - .openRawDrawing(); + .setLimitRect(limit, exclude) + .openRawDrawing(); touchHelper.setStrokeStyle(TouchHelper.STROKE_STYLE_PENCIL); } public Rect getRelativeRect(final View parentView, final View childView) { - int [] parent = new int[2]; - int [] child = new int[2]; + int[] parent = new int[2]; + int[] child = new int[2]; parentView.getLocationOnScreen(parent); childView.getLocationOnScreen(child); Rect rect = new Rect(); @@ -163,22 +159,21 @@ public Rect getRelativeRect(final View parentView, final View childView) { @Override public void onClick(View v) { - if (v.equals(buttonPen)) { + if (v.equals(binding.buttonPen)) { touchHelper.setRawDrawingEnabled(true); return; - } else if (v.equals(buttonEraser)) { + } else if (v.equals(binding.buttonEraser)) { touchHelper.setRawDrawingEnabled(false); - webView.reload(); + binding.surfaceview.reload(); return; } } - private RawInputCallback callback = new RawInputCallback() { @Override public void onBeginRawDrawing(boolean b, TouchPoint touchPoint) { Log.d(TAG, "onBeginRawDrawing"); - Log.d(TAG,touchPoint.getX() +", " +touchPoint.getY()); + Log.d(TAG, touchPoint.getX() + ", " + touchPoint.getY()); TouchUtils.disableFingerTouch(getApplicationContext()); } @@ -191,7 +186,7 @@ public void onEndRawDrawing(boolean b, TouchPoint touchPoint) { @Override public void onRawDrawingTouchPointMoveReceived(TouchPoint touchPoint) { Log.d(TAG, "onRawDrawingTouchPointMoveReceived"); - Log.d(TAG,touchPoint.getX() +", " +touchPoint.getY()); + Log.d(TAG, touchPoint.getX() + ", " + touchPoint.getY()); } @Override diff --git a/app/src/main/res/layout/activity_app_optimize.xml b/app/src/main/res/layout/activity_app_optimize.xml index 4ad0d3b0..bc18453e 100644 --- a/app/src/main/res/layout/activity_app_optimize.xml +++ b/app/src/main/res/layout/activity_app_optimize.xml @@ -1,43 +1,48 @@ - - - - - - - - - - -