/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.launcher3; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.util.AttributeSet; import android.util.Log; import android.util.TypedValue; import android.view.Gravity; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; public class WeightWatcher extends LinearLayout { private static final int RAM_GRAPH_RSS_COLOR = 0xFF990000; private static final int RAM_GRAPH_PSS_COLOR = 0xFF99CC00; private static final int TEXT_COLOR = 0xFFFFFFFF; private static final int BACKGROUND_COLOR = 0xc0000000; private static final int UPDATE_RATE = 5000; private static final int MSG_START = 1; private static final int MSG_STOP = 2; private static final int MSG_UPDATE = 3; static int indexOf(int[] a, int x) { for (int i=0; i 0) { sec -= days * 86400; sb.append(days); sb.append("d"); } long hours = sec / 3600; if (hours > 0) { sec -= hours * 3600; sb.append(hours); sb.append("h"); } long mins = sec / 60; if (mins > 0) { sec -= mins * 60; sb.append(mins); sb.append("m"); } sb.append(sec); sb.append("s"); return sb.toString(); } public void update() { //Log.v("WeightWatcher.ProcessWatcher", // "MSG_UPDATE pss=" + mMemInfo.currentPss); mText.setText("(" + mPid + (mPid == android.os.Process.myPid() ? "/A" // app : "/S") // service + ") up " + getUptimeString() + " P=" + mMemInfo.currentPss + " U=" + mMemInfo.currentUss ); mRamGraph.invalidate(); } public class GraphView extends View { Paint pssPaint, ussPaint, headPaint; public GraphView(Context context, AttributeSet attrs) { super(context, attrs); pssPaint = new Paint(); pssPaint.setColor(RAM_GRAPH_PSS_COLOR); ussPaint = new Paint(); ussPaint.setColor(RAM_GRAPH_RSS_COLOR); headPaint = new Paint(); headPaint.setColor(Color.WHITE); } public GraphView(Context context) { this(context, null); } @Override public void onDraw(Canvas c) { int w = c.getWidth(); int h = c.getHeight(); if (mMemInfo == null) return; final int N = mMemInfo.pss.length; final float barStep = (float) w / N; final float barWidth = Math.max(1, barStep); final float scale = (float) h / mMemInfo.max; int i; float x; for (i=0; i