linuxman94

fixed (i think) tatk 3

Feb 18th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2012, ParanoidAndroid 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.systemui.statusbar.policy;
  18.  
  19. import android.content.BroadcastReceiver;
  20. import android.content.Context;
  21. import android.content.Intent;
  22. import android.content.IntentFilter;
  23. import android.content.pm.PackageManager;
  24. import android.text.format.DateFormat;
  25. import android.net.ConnectivityManager;
  26. import android.net.NetworkInfo;
  27. import android.net.wifi.WifiInfo;
  28. import android.net.wifi.WifiManager;
  29. import android.service.notification.NotificationListenerService;
  30. import android.telephony.TelephonyManager;
  31.  
  32. import com.android.systemui.R;
  33.  
  34. import java.text.SimpleDateFormat;
  35. import java.util.Date;
  36.  
  37. public class PieController {
  38.  
  39. public static int LOW_BATTERY_LEVEL;
  40. public static int CRITICAL_BATTERY_LEVEL;
  41.  
  42. private static Context mContext;
  43. private static int mBatteryLevel = 0;
  44. private static int mNotificationsCount = 0;
  45. private static boolean mTelephony;
  46. private static NotificationListenerService mNotifListenerService; // Need to make new blaBla below?
  47.  
  48. private OnClockChangedListener mClockChangedListener;
  49.  
  50. private BroadcastReceiver mBatteryReceiver = new BroadcastReceiver(){
  51. @Override
  52. public void onReceive(Context arg0, Intent intent) {
  53. mBatteryLevel = intent.getIntExtra("level", 0);
  54. }
  55. };
  56.  
  57. private final BroadcastReceiver mClockReceiver = new BroadcastReceiver() {
  58. @Override
  59. public void onReceive(Context context, Intent intent) {
  60. mClockChangedListener.onChange(getSimpleTime());
  61. }
  62. };
  63.  
  64. public interface OnClockChangedListener {
  65. public abstract void onChange(String s);
  66. }
  67.  
  68. public PieController(Context context) {
  69. mContext = context;
  70. mContext.registerReceiver(mBatteryReceiver,
  71. new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
  72. IntentFilter filter = new IntentFilter();
  73. filter.addAction(Intent.ACTION_TIME_TICK);
  74. filter.addAction(Intent.ACTION_TIME_CHANGED);
  75. mContext.registerReceiver(mClockReceiver, filter);
  76. LOW_BATTERY_LEVEL = mContext.getResources().getInteger(
  77. com.android.internal.R.integer.config_lowBatteryWarningLevel);
  78. CRITICAL_BATTERY_LEVEL = mContext.getResources().getInteger(
  79. com.android.internal.R.integer.config_criticalBatteryWarningLevel);
  80. mTelephony = mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
  81. mNotifListenerService = //do the getting here.
  82. }
  83.  
  84. public void setOnClockChangedListener(OnClockChangedListener l){
  85. mClockChangedListener = l;
  86. }
  87.  
  88. public boolean supportsTelephony() {
  89. return mTelephony;
  90. }
  91.  
  92. public int getNotificationsCount() {
  93. return mNotificationsCount;
  94. }
  95.  
  96. public static String getWifiSsid() {
  97. String ssid = mContext.getString(R.string.quick_settings_wifi_not_connected);
  98. ConnectivityManager connManager = (ConnectivityManager) mContext
  99. .getSystemService(Context.CONNECTIVITY_SERVICE);
  100. NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
  101. if (networkInfo.isConnected()) {
  102. final WifiManager wifiManager = (WifiManager) mContext
  103. .getSystemService(Context.WIFI_SERVICE);
  104. final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
  105. ssid = NetworkController.huntForSsid(wifiManager, connectionInfo);
  106. }
  107. return ssid.toUpperCase();
  108. }
  109.  
  110. public static String getNetworkProvider() {
  111. String operatorName = mContext.getString(R.string.quick_settings_wifi_no_network);
  112. TelephonyManager telephonyManager = (TelephonyManager) mContext
  113. .getSystemService(Context.TELEPHONY_SERVICE);
  114. operatorName = telephonyManager.getNetworkOperatorName();
  115. if(operatorName == null) {
  116. operatorName = telephonyManager.getSimOperatorName();
  117. }
  118. return operatorName.toUpperCase();
  119. }
  120.  
  121. public static String getSimpleDate() {
  122. SimpleDateFormat sdf = new SimpleDateFormat(
  123. mContext.getString(R.string.pie_date_format));
  124. String date = sdf.format(new Date());
  125. return date.toUpperCase();
  126. }
  127.  
  128. public static boolean is24Hours() {
  129. return DateFormat.is24HourFormat(mContext);
  130. }
  131.  
  132. public static String getSimpleTime() {
  133. SimpleDateFormat sdf = new SimpleDateFormat(
  134. mContext.getString(is24Hours() ? R.string.pie_hour_format_24 :
  135. R.string.pie_hour_format_12));
  136. String amPm = sdf.format(new Date());
  137. return amPm.toUpperCase();
  138. }
  139.  
  140. public static String getAmPm() {
  141. String amPm = "";
  142. if(!is24Hours()) {
  143. SimpleDateFormat sdf = new SimpleDateFormat(
  144. mContext.getString(R.string.pie_am_pm));
  145. amPm = sdf.format(new Date()).toUpperCase();
  146. }
  147. return amPm;
  148. }
  149.  
  150. public static int getBatteryLevel() {
  151. return mBatteryLevel;
  152. }
  153.  
  154. public static String getBatteryLevelReadable() {
  155. return mContext.getString(R.string.battery_low_percent_format, mBatteryLevel)
  156. .toUpperCase();
  157. }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment