From ffa5e54ac0dfa734371e095150350df2088bee8b Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sun, 12 Jun 2022 07:51:08 +0200 Subject: [PATCH] Remove ButterKnife --- SampleCode/app/build.gradle | 6 +- .../sample/demo/utmiss/UTMISSActivity.java | 94 +++++++------------ 2 files changed, 37 insertions(+), 63 deletions(-) diff --git a/SampleCode/app/build.gradle b/SampleCode/app/build.gradle index 7e08a80b..20e751b5 100644 --- a/SampleCode/app/build.gradle +++ b/SampleCode/app/build.gradle @@ -25,6 +25,10 @@ android { } } + buildFeatures { + viewBinding = true + } + buildTypes { release { shrinkResources false @@ -94,8 +98,6 @@ dependencies { implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.annotation:annotation:1.3.0' - implementation 'com.jakewharton:butterknife:10.0.0' - annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0' implementation "androidx.core:core-ktx:1.8.0" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" diff --git a/SampleCode/app/src/main/java/com/dji/sdk/sample/demo/utmiss/UTMISSActivity.java b/SampleCode/app/src/main/java/com/dji/sdk/sample/demo/utmiss/UTMISSActivity.java index 0ef7283f..d4cf5751 100644 --- a/SampleCode/app/src/main/java/com/dji/sdk/sample/demo/utmiss/UTMISSActivity.java +++ b/SampleCode/app/src/main/java/com/dji/sdk/sample/demo/utmiss/UTMISSActivity.java @@ -3,20 +3,14 @@ import android.os.Bundle; import android.text.TextUtils; import android.view.View; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; -import com.dji.sdk.sample.R; +import com.dji.sdk.sample.databinding.ActivityUtmissBinding; import java.io.File; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; import dji.common.error.DJIError; import dji.sdk.utmiss.UTMISSFlightDataUploadStatus; import dji.sdk.utmiss.UTMISSManager; @@ -26,33 +20,30 @@ public class UTMISSActivity extends AppCompatActivity { - TextView mTvDbPath; - TextView mTvStatus; - TextView mTvInfo; - - EditText mEdtTokenKey; - EditText mEdtManufactureId; - EditText mEdtUasId; - Button mBtnInit; - String dbPath; + private ActivityUtmissBinding binding; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_utmiss); - ButterKnife.bind(this); - initUI(); - } + binding = ActivityUtmissBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + binding.btnStart.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + start(); + } + }); - private void initUI(){ - mTvDbPath = findViewById(R.id.txt_db_path); - mTvStatus = findViewById(R.id.txt_status); - mTvInfo = findViewById(R.id.txt_info); - mEdtTokenKey = findViewById(R.id.edt_token_key); - mEdtManufactureId = findViewById(R.id.edt_manufactureId); - mEdtUasId = findViewById(R.id.edt_uasId); - mBtnInit = findViewById(R.id.btn_start); + binding.btnStop.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + stop(); + } + }); init(); } @@ -67,51 +58,35 @@ private void init() { showToast("dbPath dir create failed!"); } } - mTvDbPath.setText(String.format("db path->%s\nlog path->%s", dbPath, UTMISSManager.getInstance().getUtmissLogPath())); - mEdtManufactureId.setText("test"); - mEdtUasId.setText("UAS-DEFAULT"); + binding.txtDbPath.setText(String.format("db path->%s\nlog path->%s", dbPath, UTMISSManager.getInstance().getUtmissLogPath())); + binding.edtManufactureId.setText("test"); + binding.edtUasId.setText("UAS-DEFAULT"); UTMISSFlightDataUploadStatus uploadStatus = UTMISSManager.getInstance().getUploadStatus(); - mTvStatus.setText(String.format("current status is %s", uploadStatus.toString())); + binding.txtStatus.setText(String.format("current status is %s", uploadStatus.toString())); if (uploadStatus != UTMISSFlightDataUploadStatus.UNKNOWN) { changeUI(); } } - - @OnClick({R.id.btn_start, R.id.btn_stop}) - public void onClick(View v) { - switch (v.getId()) { - case R.id.btn_start: - start(); - break; - case R.id.btn_stop: - stop(); - break; - default: - throw new IllegalArgumentException("some btn click not implementation!"); - } - } - private void stop() { UTMISSManager.getInstance().stopToUpload(); changeInitBtnState(true); } - private void start() { - String tokenKey = mEdtTokenKey.getText().toString().trim(); + String tokenKey = binding.edtTokenKey.getText().toString().trim(); if (TextUtils.isEmpty(tokenKey)) { showToast("pls enter token key first"); return; } - String manufactureId = mEdtManufactureId.getText().toString().trim(); + String manufactureId = binding.edtManufactureId.getText().toString().trim(); if (TextUtils.isEmpty(manufactureId)) { showToast("pls enter manufactureId first"); return; } - String uasId = mEdtManufactureId.getText().toString().trim(); + String uasId = binding.edtManufactureId.getText().toString().trim(); if (TextUtils.isEmpty(uasId)) { showToast("pls enter uasId first"); return; @@ -128,18 +103,15 @@ private void start() { private void changeUI() { changeInitBtnState(false); - UTMISSManager.getInstance().setUTMISSFlightDataUpdatedUploadStatusCallback(status -> mTvStatus.setText(String.format("current status is %s", status.toString()))); + UTMISSManager.getInstance().setUTMISSFlightDataUpdatedUploadStatusCallback(status -> binding.txtStatus.setText(String.format("current status is %s", status.toString()))); } private void changeInitBtnState(boolean enable) { - mTvInfo.setVisibility(enable ? View.GONE : View.VISIBLE); - mBtnInit.setEnabled(enable); - mEdtTokenKey.setEnabled(enable); - mEdtManufactureId.setEnabled(enable); - mEdtUasId.setEnabled(enable); + binding.txtInfo.setVisibility(enable ? View.GONE : View.VISIBLE); + binding.btnStart.setEnabled(enable); + binding.edtTokenKey.setEnabled(enable); + binding.edtManufactureId.setEnabled(enable); + binding.edtUasId.setEnabled(enable); } - - - -} \ No newline at end of file +}