1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.phone; 18 19 import com.android.phone.R; 20 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.IntentFilter; 24 import android.os.Bundle; 25 import android.preference.Preference; 26 import android.preference.PreferenceActivity; 27 import android.preference.PreferenceScreen; 28 import android.net.Uri; 29 import android.net.ThrottleManager; 30 import android.util.Log; 31 32 33 /** 34 * Lists the data usage and throttle settings 35 */ 36 public class DataUsage extends PreferenceActivity { 37 38 private Preference mCurrentUsagePref; 39 private Preference mTimeFramePref; 40 private Preference mThrottleRatePref; 41 private Preference mHelpPref; 42 private String mHelpUri; 43 44 private DataUsageListener mDataUsageListener; 45 private ThrottleManager mThrottleManager; 46 47 @Override 48 protected void onCreate(Bundle icicle) { 49 super.onCreate(icicle); 50 51 mThrottleManager = (ThrottleManager) getSystemService(Context.THROTTLE_SERVICE); 52 53 addPreferencesFromResource(R.xml.data_usage_settings); 54 55 mCurrentUsagePref = findPreference("throttle_current_usage"); 56 mTimeFramePref = findPreference("throttle_time_frame"); 57 mThrottleRatePref = findPreference("throttle_rate"); 58 mHelpPref = findPreference("throttle_help"); 59 60 mHelpUri = mThrottleManager.getHelpUri(); 61 if (mHelpUri == null ) { 62 getPreferenceScreen().removePreference(mHelpPref); 63 } else { 64 mHelpPref.setSummary(getString(R.string.throttle_help_subtext)); 65 } 66 67 mDataUsageListener = new DataUsageListener(this, mCurrentUsagePref, 68 mTimeFramePref, mThrottleRatePref); 69 } 70 71 @Override 72 protected void onResume() { 73 super.onResume(); 74 mDataUsageListener.resume(); 75 } 76 77 @Override 78 protected void onPause() { 79 super.onPause(); 80 mDataUsageListener.pause(); 81 } 82 83 84 @Override 85 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { 86 87 if (preference == mHelpPref) { 88 try { 89 Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mHelpUri)); 90 startActivity(myIntent); 91 } catch (Exception e) { 92 ; 93 } 94 } 95 96 return true; 97 } 98 } 99