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:
@@ -33,6 +33,7 @@ import android.widget.TextView;
|
|||||||
import androidx.appcompat.widget.AppCompatImageView;
|
import androidx.appcompat.widget.AppCompatImageView;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.Utils;
|
import com.android.settingslib.Utils;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -59,6 +60,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
|||||||
private int mSelectedIndex;
|
private int mSelectedIndex;
|
||||||
private float mTrapezoidVOffset;
|
private float mTrapezoidVOffset;
|
||||||
private float mTrapezoidHOffset;
|
private float mTrapezoidHOffset;
|
||||||
|
private boolean mIsSlotsClickable;
|
||||||
|
|
||||||
// Colors for drawing the trapezoid shape and dividers.
|
// Colors for drawing the trapezoid shape and dividers.
|
||||||
private int mTrapezoidColor;
|
private int mTrapezoidColor;
|
||||||
private int mTrapezoidSolidColor;
|
private int mTrapezoidSolidColor;
|
||||||
@@ -73,7 +76,6 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
|||||||
private final Rect[] mTimestampsBounds =
|
private final Rect[] mTimestampsBounds =
|
||||||
new Rect[] {new Rect(), new Rect(), new Rect(), new Rect()};
|
new Rect[] {new Rect(), new Rect(), new Rect(), new Rect()};
|
||||||
|
|
||||||
|
|
||||||
private int[] mLevels;
|
private int[] mLevels;
|
||||||
private Paint mTextPaint;
|
private Paint mTextPaint;
|
||||||
private Paint mDividerPaint;
|
private Paint mDividerPaint;
|
||||||
@@ -92,9 +94,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
|||||||
initializeColors(context);
|
initializeColors(context);
|
||||||
// Registers the click event listener.
|
// Registers the click event listener.
|
||||||
setOnClickListener(this);
|
setOnClickListener(this);
|
||||||
setClickable(false);
|
|
||||||
setSelectedIndex(SELECTED_INDEX_ALL);
|
setSelectedIndex(SELECTED_INDEX_ALL);
|
||||||
setTrapezoidCount(DEFAULT_TRAPEZOID_COUNT);
|
setTrapezoidCount(DEFAULT_TRAPEZOID_COUNT);
|
||||||
|
setClickable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the total trapezoid count for drawing. */
|
/** Sets the total trapezoid count for drawing. */
|
||||||
@@ -241,6 +243,23 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
|||||||
view.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK);
|
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) {
|
private void initializeColors(Context context) {
|
||||||
setBackgroundColor(Color.TRANSPARENT);
|
setBackgroundColor(Color.TRANSPARENT);
|
||||||
mTrapezoidSolidColor = Utils.getColorAccentDefaultColor(context);
|
mTrapezoidSolidColor = Utils.getColorAccentDefaultColor(context);
|
||||||
|
@@ -260,10 +260,10 @@ public final class ConvertUtils {
|
|||||||
diffEntry.setTotalConsumePower(totalConsumePower);
|
diffEntry.setTotalConsumePower(totalConsumePower);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
insert24HoursData(BatteryChartView.SELECTED_INDEX_ALL, resultMap);
|
||||||
if (purgeLowPercentageAndFakeData) {
|
if (purgeLowPercentageAndFakeData) {
|
||||||
purgeLowPercentageAndFakeData(resultMap);
|
purgeLowPercentageAndFakeData(resultMap);
|
||||||
}
|
}
|
||||||
insert24HoursData(BatteryChartView.SELECTED_INDEX_ALL, resultMap);
|
|
||||||
return resultMap;
|
return resultMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -132,6 +132,11 @@ public interface PowerUsageFeatureProvider {
|
|||||||
*/
|
*/
|
||||||
boolean isChartGraphEnabled(Context context);
|
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.
|
* Returns battery history data with corresponding timestamp key.
|
||||||
*/
|
*/
|
||||||
|
@@ -158,6 +158,11 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isChartGraphSlotsEnabled(Context context) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context) {
|
public Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context) {
|
||||||
return null;
|
return null;
|
||||||
|
@@ -246,12 +246,10 @@ public final class ConvertUtilsTest {
|
|||||||
assertBatteryDiffEntry(entryList.get(0), 75, 40L, 50L);
|
assertBatteryDiffEntry(entryList.get(0), 75, 40L, 50L);
|
||||||
// Verifies the last 24 hours aggregate result.
|
// Verifies the last 24 hours aggregate result.
|
||||||
entryList = purgedResultMap.get(Integer.valueOf(-1));
|
entryList = purgedResultMap.get(Integer.valueOf(-1));
|
||||||
assertThat(entryList).hasSize(2);
|
assertThat(entryList).hasSize(1);
|
||||||
// Verifies the fake data is cleared out.
|
// Verifies the fake data is cleared out.
|
||||||
assertThat(entryList.get(0).getPackageName())
|
assertThat(entryList.get(0).getPackageName())
|
||||||
.isNotEqualTo(ConvertUtils.FAKE_PACKAGE_NAME);
|
.isNotEqualTo(ConvertUtils.FAKE_PACKAGE_NAME);
|
||||||
assertThat(entryList.get(1).getPackageName())
|
|
||||||
.isNotEqualTo(ConvertUtils.FAKE_PACKAGE_NAME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user