Build a bridge to control whether the graph is clickable or not

Create a bridge to read phenotype flag from GoogleSettings to control
whether each time slot in the graph is clickable or not.

Bug: 185308803
Test: make SettingsRoboTests
Change-Id: If8b58dcaa50ad5fb6b447ca5b7146639ee31a9df
This commit is contained in:
ykhung
2021-05-08 22:36:51 +08:00
committed by YUKAI HUNG
parent 5b27fd923a
commit d8d5335096
5 changed files with 33 additions and 6 deletions

View File

@@ -33,6 +33,7 @@ import android.widget.TextView;
import androidx.appcompat.widget.AppCompatImageView;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.Utils;
import java.util.Locale;
@@ -59,6 +60,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private int mSelectedIndex;
private float mTrapezoidVOffset;
private float mTrapezoidHOffset;
private boolean mIsSlotsClickable;
// Colors for drawing the trapezoid shape and dividers.
private int mTrapezoidColor;
private int mTrapezoidSolidColor;
@@ -73,7 +76,6 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private final Rect[] mTimestampsBounds =
new Rect[] {new Rect(), new Rect(), new Rect(), new Rect()};
private int[] mLevels;
private Paint mTextPaint;
private Paint mDividerPaint;
@@ -92,9 +94,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
initializeColors(context);
// Registers the click event listener.
setOnClickListener(this);
setClickable(false);
setSelectedIndex(SELECTED_INDEX_ALL);
setTrapezoidCount(DEFAULT_TRAPEZOID_COUNT);
setClickable(false);
}
/** Sets the total trapezoid count for drawing. */
@@ -241,6 +243,23 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
view.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK);
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
final Context context = mContext;
mIsSlotsClickable =
FeatureFactory.getFactory(context)
.getPowerUsageFeatureProvider(context)
.isChartGraphSlotsEnabled(context);
Log.d(TAG, "isChartGraphSlotsEnabled:" + mIsSlotsClickable);
setClickable(isClickable());
}
@Override
public void setClickable(boolean clickable) {
super.setClickable(mIsSlotsClickable && clickable);
}
private void initializeColors(Context context) {
setBackgroundColor(Color.TRANSPARENT);
mTrapezoidSolidColor = Utils.getColorAccentDefaultColor(context);