Android Open Source - ShortcutsOfPower_Android N P Widget Mobile Data






From Project

Back to project page ShortcutsOfPower_Android.

License

The source code is released under:

GNU General Public License

If you think the Android project ShortcutsOfPower_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.networkprofiles.widget;
/* w w w .j a va 2s. co m*/
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.widget.RemoteViews;

import com.networkprofiles.R;
import com.networkprofiles.utils.NPReceiver;

public class NPWidgetMobileData extends AppWidgetProvider {

  TelephonyManager telephonyManager;
  
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] widgetIds) {
    RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.npwidgetmobiledata);
    
    Intent clickMobile = new Intent(NPReceiver.ACTION_NP_WIDGET_MOBILE);
    clickMobile.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
    PendingIntent pendingMobile = PendingIntent.getBroadcast(context.getApplicationContext(), 0, clickMobile, PendingIntent.FLAG_UPDATE_CURRENT);
    remote.setOnClickPendingIntent(R.id.textWidgetMobileData, pendingMobile);
    
    atStart(context, remote);
    
    appWidgetManager.updateAppWidget(widgetIds, remote);
  }
  
  public void onEnabled(Context context) {
    Intent i = new Intent("android.appwidget.action.APPWIDGET_UPDATE");
    PendingIntent pendingI = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    try {
      pendingI.send();
    } catch (CanceledException e) {
      e.printStackTrace();
    }
  }
  
  public void onDisabled(Context context) {
    
  }
  
  private void atStart(Context context, RemoteViews remote) {
//    telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//    //set the TextView for Mobile data
//    if(telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED || telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTING) {
//      remote.setTextViewText(R.id.textWidgetMobileData, "Data ON");
//    }
//    if(telephonyManager.getDataState() == TelephonyManager.DATA_DISCONNECTED) {
//      remote.setTextViewText(R.id.textWidgetMobileData, "Data OFF");
//    }
  }
}




Java Source Code List

com.networkprofiles.MainNP.java
com.networkprofiles.SOPEula.java
com.networkprofiles.utils.ConstantsNP.java
com.networkprofiles.utils.MyNetControll.java
com.networkprofiles.utils.NPReceiver.java
com.networkprofiles.widget.NPWidgetCell.java
com.networkprofiles.widget.NPWidgetDisplay.java
com.networkprofiles.widget.NPWidgetGps.java
com.networkprofiles.widget.NPWidgetMobileData.java
com.networkprofiles.widget.NPWidgetService.java
com.networkprofiles.widget.NPWidgetSound.java