Merge "Start cleaning up percentage formatting in Settings." into lmp-dev

This commit is contained in:
Elliott Hughes
2014-09-08 23:26:20 +00:00
committed by Android (Google) Code Review
9 changed files with 95 additions and 114 deletions

View File

@@ -39,6 +39,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.Utils;
import java.util.ArrayList;
import java.util.Collections;
@@ -72,11 +73,6 @@ public class ProcessStatsDetail extends Fragment implements Button.OnClickListen
private ViewGroup mDetailsParent;
private ViewGroup mServicesParent;
public static String makePercentString(Resources res, long amount, long total) {
final double percent = (((double)amount) / total) * 100;
return res.getString(R.string.percentage, (int) Math.round(percent));
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -116,7 +112,7 @@ public class ProcessStatsDetail extends Fragment implements Button.OnClickListen
final double percentOfWeight = (((double)mEntry.mWeight) / mMaxWeight) * 100;
int appLevel = (int) Math.ceil(percentOfWeight);
String appLevelText = makePercentString(getResources(), mEntry.mDuration, mTotalTime);
String appLevelText = Utils.formatPercentage(mEntry.mDuration, mTotalTime);
// Set all values in the header.
final TextView summary = (TextView) mRootView.findViewById(android.R.id.summary);
@@ -203,7 +199,7 @@ public class ProcessStatsDetail extends Fragment implements Button.OnClickListen
Formatter.formatShortFileSize(getActivity(),
(mUseUss ? mEntry.mMaxUss : mEntry.mMaxPss) * 1024));
addDetailsItem(mDetailsParent, getResources().getText(R.string.process_stats_run_time),
makePercentString(getResources(), mEntry.mDuration, mTotalTime));
Utils.formatPercentage(mEntry.mDuration, mTotalTime));
}
final static Comparator<ProcStatsEntry.Service> sServiceCompare
@@ -265,10 +261,8 @@ public class ProcessStatsDetail extends Fragment implements Button.OnClickListen
if (tail >= 0 && tail < (label.length()-1)) {
label = label.substring(tail+1);
}
long duration = service.mDuration;
final double percentOfTime = (((double)duration) / mTotalTime) * 100;
addDetailsItem(mServicesParent, label, getActivity().getResources().getString(
R.string.percentage, (int) Math.ceil(percentOfTime)));
String percentage = Utils.formatPercentage(service.mDuration, mTotalTime);
addDetailsItem(mServicesParent, label, percentage);
}
}
}

View File

@@ -26,6 +26,7 @@ import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.Utils;
public class ProcessStatsPreference extends Preference {
private ProcStatsEntry mEntry;
@@ -61,8 +62,7 @@ public class ProcessStatsPreference extends Preference {
public void setPercent(double percentOfWeight, double percentOfTime) {
mProgress = (int) Math.ceil(percentOfWeight);
mProgressText = getContext().getResources().getString(
R.string.percentage, (int) Math.round(percentOfTime));
mProgressText = Utils.formatPercentage((int) percentOfTime);
notifyChanged();
}

View File

@@ -43,7 +43,7 @@ import com.android.internal.app.ProcessStats;
import com.android.internal.util.MemInfoReader;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.Utils;
import com.android.settings.Utils;
import java.io.IOException;
import java.io.InputStream;