Search in sources :

Example 1 with NetworkCycleChartData

use of com.android.settingslib.net.NetworkCycleChartData in project android_packages_apps_Settings by omnirom.

the class DataUsageListTest method startAppDataUsage_shouldAddCyclesInfoToLaunchArguments.

@Test
public void startAppDataUsage_shouldAddCyclesInfoToLaunchArguments() {
    final long startTime = 1521583200000L;
    final long endTime = 1521676800000L;
    final List<NetworkCycleChartData> data = new ArrayList<>();
    final NetworkCycleChartData.Builder builder = new NetworkCycleChartData.Builder();
    builder.setStartTime(startTime).setEndTime(endTime);
    data.add(builder.build());
    ReflectionHelpers.setField(mDataUsageList, "mCycleData", data);
    final Spinner spinner = mock(Spinner.class);
    when(spinner.getSelectedItemPosition()).thenReturn(0);
    ReflectionHelpers.setField(mDataUsageList, "mCycleSpinner", spinner);
    final ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
    mDataUsageList.startAppDataUsage(new AppItem());
    verify(mActivity).startActivity(intent.capture());
    final Bundle arguments = intent.getValue().getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
    assertThat(arguments.getLong(AppDataUsage.ARG_SELECTED_CYCLE)).isEqualTo(endTime);
    final ArrayList<Long> cycles = (ArrayList) arguments.getSerializable(AppDataUsage.ARG_NETWORK_CYCLES);
    assertThat(cycles).hasSize(2);
    assertThat(cycles.get(0)).isEqualTo(endTime);
    assertThat(cycles.get(1)).isEqualTo(startTime);
}
Also used : Spinner(android.widget.Spinner) Bundle(android.os.Bundle) NetworkCycleChartData(com.android.settingslib.net.NetworkCycleChartData) ArrayList(java.util.ArrayList) Intent(android.content.Intent) AppItem(com.android.settingslib.AppItem) Test(org.junit.Test)

Example 2 with NetworkCycleChartData

use of com.android.settingslib.net.NetworkCycleChartData in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DataUsageList method startAppDataUsage.

@VisibleForTesting
void startAppDataUsage(AppItem item) {
    final Bundle args = new Bundle();
    args.putParcelable(AppDataUsage.ARG_APP_ITEM, item);
    args.putParcelable(AppDataUsage.ARG_NETWORK_TEMPLATE, mTemplate);
    if (mCycles == null) {
        mCycles = new ArrayList<>();
        for (NetworkCycleChartData data : mCycleData) {
            if (mCycles.isEmpty()) {
                mCycles.add(data.getEndTime());
            }
            mCycles.add(data.getStartTime());
        }
    }
    args.putSerializable(AppDataUsage.ARG_NETWORK_CYCLES, mCycles);
    args.putLong(AppDataUsage.ARG_SELECTED_CYCLE, mCycleData.get(mCycleSpinner.getSelectedItemPosition()).getEndTime());
    new SubSettingLauncher(getContext()).setDestination(AppDataUsage.class.getName()).setTitleRes(R.string.data_usage_app_summary_title).setArguments(args).setSourceMetricsCategory(getMetricsCategory()).launch();
}
Also used : SubSettingLauncher(com.android.settings.core.SubSettingLauncher) Bundle(android.os.Bundle) NetworkCycleChartData(com.android.settingslib.net.NetworkCycleChartData) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 3 with NetworkCycleChartData

use of com.android.settingslib.net.NetworkCycleChartData in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DataUsageListTest method startAppDataUsage_shouldAddCyclesInfoToLaunchArguments.

@Test
public void startAppDataUsage_shouldAddCyclesInfoToLaunchArguments() {
    final long startTime = 1521583200000L;
    final long endTime = 1521676800000L;
    final List<NetworkCycleChartData> data = new ArrayList<>();
    final NetworkCycleChartData.Builder builder = new NetworkCycleChartData.Builder();
    builder.setStartTime(startTime).setEndTime(endTime);
    data.add(builder.build());
    ReflectionHelpers.setField(mDataUsageList, "mCycleData", data);
    final Spinner spinner = mock(Spinner.class);
    when(spinner.getSelectedItemPosition()).thenReturn(0);
    ReflectionHelpers.setField(mDataUsageList, "mCycleSpinner", spinner);
    final ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
    mDataUsageList.startAppDataUsage(new AppItem());
    verify(mActivity).startActivity(intent.capture());
    final Bundle arguments = intent.getValue().getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
    assertThat(arguments.getLong(AppDataUsage.ARG_SELECTED_CYCLE)).isEqualTo(endTime);
    final ArrayList<Long> cycles = (ArrayList) arguments.getSerializable(AppDataUsage.ARG_NETWORK_CYCLES);
    assertThat(cycles).hasSize(2);
    assertThat(cycles.get(0)).isEqualTo(endTime);
    assertThat(cycles.get(1)).isEqualTo(startTime);
}
Also used : Spinner(android.widget.Spinner) Bundle(android.os.Bundle) NetworkCycleChartData(com.android.settingslib.net.NetworkCycleChartData) ArrayList(java.util.ArrayList) Intent(android.content.Intent) AppItem(com.android.settingslib.AppItem) Test(org.junit.Test)

Example 4 with NetworkCycleChartData

use of com.android.settingslib.net.NetworkCycleChartData in project android_packages_apps_Settings by omnirom.

the class DataUsageList method startAppDataUsage.

@VisibleForTesting
void startAppDataUsage(AppItem item) {
    final Bundle args = new Bundle();
    args.putParcelable(AppDataUsage.ARG_APP_ITEM, item);
    args.putParcelable(AppDataUsage.ARG_NETWORK_TEMPLATE, mTemplate);
    if (mCycles == null) {
        mCycles = new ArrayList<>();
        for (NetworkCycleChartData data : mCycleData) {
            if (mCycles.isEmpty()) {
                mCycles.add(data.getEndTime());
            }
            mCycles.add(data.getStartTime());
        }
    }
    args.putSerializable(AppDataUsage.ARG_NETWORK_CYCLES, mCycles);
    args.putLong(AppDataUsage.ARG_SELECTED_CYCLE, mCycleData.get(mCycleSpinner.getSelectedItemPosition()).getEndTime());
    new SubSettingLauncher(getContext()).setDestination(AppDataUsage.class.getName()).setTitleRes(R.string.data_usage_app_summary_title).setArguments(args).setSourceMetricsCategory(getMetricsCategory()).launch();
}
Also used : SubSettingLauncher(com.android.settings.core.SubSettingLauncher) Bundle(android.os.Bundle) NetworkCycleChartData(com.android.settingslib.net.NetworkCycleChartData) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

Bundle (android.os.Bundle)4 NetworkCycleChartData (com.android.settingslib.net.NetworkCycleChartData)4 Intent (android.content.Intent)2 Spinner (android.widget.Spinner)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)2 AppItem (com.android.settingslib.AppItem)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2