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);

View File

@@ -260,10 +260,10 @@ public final class ConvertUtils {
diffEntry.setTotalConsumePower(totalConsumePower);
}
}
insert24HoursData(BatteryChartView.SELECTED_INDEX_ALL, resultMap);
if (purgeLowPercentageAndFakeData) {
purgeLowPercentageAndFakeData(resultMap);
}
insert24HoursData(BatteryChartView.SELECTED_INDEX_ALL, resultMap);
return resultMap;
}

View File

@@ -132,6 +132,11 @@ public interface PowerUsageFeatureProvider {
*/
boolean isChartGraphEnabled(Context context);
/**
* Checks whether we should show usage information by slots or not.
*/
boolean isChartGraphSlotsEnabled(Context context);
/**
* Returns battery history data with corresponding timestamp key.
*/

View File

@@ -158,6 +158,11 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
return false;
}
@Override
public boolean isChartGraphSlotsEnabled(Context context) {
return false;
}
@Override
public Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context) {
return null;

View File

@@ -246,12 +246,10 @@ public final class ConvertUtilsTest {
assertBatteryDiffEntry(entryList.get(0), 75, 40L, 50L);
// Verifies the last 24 hours aggregate result.
entryList = purgedResultMap.get(Integer.valueOf(-1));
assertThat(entryList).hasSize(2);
assertThat(entryList).hasSize(1);
// Verifies the fake data is cleared out.
assertThat(entryList.get(0).getPackageName())
.isNotEqualTo(ConvertUtils.FAKE_PACKAGE_NAME);
assertThat(entryList.get(1).getPackageName())
.isNotEqualTo(ConvertUtils.FAKE_PACKAGE_NAME);
}
@Test