Example usage for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID

List of usage examples for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID

Introduction

In this page you can find the example usage for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID.

Prototype

String EXTRA_APPWIDGET_ID

To view the source code for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID.

Click Source Link

Document

An intent extra that contains one appWidgetId.

Usage

From source file:net.niyonkuru.koodroid.appwidget.WidgetConfigureActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mAppWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
            AppWidgetManager.INVALID_APPWIDGET_ID);

    final Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);

    if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
        setResult(RESULT_CANCELED, resultValue);
        finish();/* www.j a v  a2 s  .  com*/
    }

    // Create an empty adapter we will use to display the loaded data.
    mAdapter = new SimpleCursorAdapter(this, android.R.layout.select_dialog_singlechoice, null,
            new String[] { Subscribers.SUBSCRIBER_ID }, new int[] { android.R.id.text1 }, 0);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.choose_subscriber_title);

    builder.setSingleChoiceItems(mAdapter, 0, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int position) {
            final Cursor cursor = mAdapter.getCursor();
            cursor.moveToPosition(position);

            ContentValues values = new ContentValues(1);
            values.put(Settings.SUBSCRIBER, cursor.getString(SubscribersQuery.SUBSCRIBER_ID));

            ContentResolver cr = getContentResolver();
            cr.insert(Settings.buildAppWidgetUri(mAppWidgetId), values);

            mResultCode = RESULT_OK;
            setResult(mResultCode, resultValue);

            dialog.dismiss();
            finish();
        }
    });

    builder.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            setResult(RESULT_CANCELED, resultValue);

            dialog.dismiss();
            finish();
        }
    });

    builder.setNegativeButton(R.string.cancel, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            dialog.cancel();
        }
    });

    mAlertDialog = builder.create();

    getSupportLoaderManager().initLoader(0, null, this);
}

From source file:org.flexlabs.widgets.dualbattery.widgetsettings.WidgetActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    startService(new Intent(this, MonitorService.class));
    Bundle extras = getIntent().getExtras();
    appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);

    fragments = new Fragment[5];
    fragments[0] = new BatteryInfoFragment();
    fragments[1] = new PropertiesFragment();
    fragments[2] = new FeedbackFragment();
    fragments[3] = new DonateFragment();
    fragments[4] = new AboutFragment();
    titles = new String[5];
    titles[0] = getString(R.string.propHeader_BatteryInfo);
    titles[1] = getString(R.string.propHeader_Properties);
    titles[2] = getString(R.string.propHeader_Feedback);
    titles[3] = getString(R.string.propHeader_Donate);
    titles[4] = getString(R.string.propHeader_About);

    int screenLayout = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
            && screenLayout > Configuration.SCREENLAYOUT_SIZE_LARGE) {
        setContentView(R.layout.preference_list_large);

        ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1,
                titles);//from w  ww.  j  ava 2  s .  c om

        mList = (ListView) findViewById(android.R.id.list);
        mList.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
        mList.setOnItemClickListener(this);
        mList.setAdapter(adapter);
        mList.setItemChecked(0, true);
        mList.performClick();
        getSupportFragmentManager().beginTransaction().replace(R.id.prefs, fragments[0]).commit();
    } else {
        setContentView(R.layout.widgetsettings);
        PagerTabAdapter mPagerAdapter = new PagerTabAdapter(getSupportFragmentManager());
        ViewPager mPager = (ViewPager) findViewById(R.id.pager);
        mPager.setAdapter(mPagerAdapter);

        PageIndicator mIndicator = (TabPageIndicator) findViewById(R.id.indicator);
        mIndicator.setViewPager(mPager);
    }

    if (WidgetSettingsContainer.getUpgradeSwappedSingle(this, appWidgetId)) {
        new AlertDialog.Builder(this).setTitle(R.string.app_name).setMessage(R.string.alert_just_swapped)
                .setPositiveButton("OK", null).show();
    }
}

From source file:net.olejon.spotcommander.WidgetActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Settings//from  w w w . j ava2s.c o m
    PreferenceManager.setDefaultValues(mContext, R.xml.settings, false);

    // Allow landscape?
    if (!mTools.allowLandscape())
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Database
    mDatabase = new MainSQLiteHelper(mContext).getReadableDatabase();

    // Intent
    setResult(RESULT_CANCELED);

    final Intent intent = getIntent();

    if (intent.getExtras() != null)
        mAppWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);

    if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
        finish();

    // Layout
    setContentView(R.layout.activity_widget);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.widget_toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_close_white_24dp);
    toolbar.setTitle(getString(R.string.widget_title));

    setSupportActionBar(toolbar);

    // Listview
    mListView = (ListView) findViewById(R.id.widget_list);

    final View listViewHeader = getLayoutInflater().inflate(R.layout.activity_main_subheader, mListView, false);
    mListView.addHeaderView(listViewHeader, null, false);

    final View listViewEmpty = findViewById(R.id.widget_empty);
    mListView.setEmptyView(listViewEmpty);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mTools.setSharedPreferencesLong("WIDGET_" + mAppWidgetId + "_COMPUTER_ID", id);

            Intent result = new Intent();
            result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
            setResult(RESULT_OK, result);

            finish();
        }
    });

    listComputers();
}

From source file:ch.fixme.status.Widget.java

protected static Intent getIntent(Context ctxt, int widgetId) {
    Intent i = new Intent(ctxt, UpdateService.class);
    i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
    return i;/*w w  w.  j  a v  a 2 s.com*/
}

From source file:com.android.mms.widget.MmsWidgetProvider.java

/**
 * Update the widget appWidgetId/*from w w  w.j ava  2  s  .c om*/
 */
private static void updateWidget(Context context, int appWidgetId) {
    if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
        Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
    }
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    PendingIntent clickIntent;

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, MmsWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent);

    remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.sms_app_label));

    // Open Mms's app conversation list when click on header
    final Intent convIntent = new Intent(context, ConversationList.class);
    clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent(context, ComposeMessageActivity.class);
    composeIntent.setAction(Intent.ACTION_SENDTO);
    clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ComposeMessageActivity.class);
    Intent msgIntent = new Intent(Intent.ACTION_VIEW);
    msgIntent.setType("vnd.android-dir/mms-sms");
    taskStackBuilder.addNextIntent(msgIntent);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
}

From source file:com.lemontruck.thermo.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Find the widget id from the intent. 
    Intent intent = getIntent();/*from  w w w. j  av  a  2 s.com*/
    Bundle extras = intent.getExtras();
    if (extras != null) {
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    }

    // If they gave us an intent without the widget id, just bail.
    if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
        Log.w(LOG, "Invalid App Id");
        finish();
    }
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager(),
            getApplicationContext().getResources());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    actionBar.setHomeButtonEnabled(false);
    //actionBar.setDisplayShowTitleEnabled(false);

    // Set the result to CANCELED.  This will cause the widget host to cancel
    // out of the widget placement if they press the back button.
    setResult(RESULT_CANCELED);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.gelakinetic.inboxwidget.InboxCheckerAppWidgetConfigure.java

/**
 * This is called when the widget needs configuring. It will check permissions, get accounts,
 * prompt the user to select an account, and save the widget
 *///w w w  .j a  v a  2  s.c  o  m
@Override
public void onResume() {
    super.onResume();

    /* Get the app widget ID we're configuring */
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
    }

    if (extras == null || mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
        /* Not configuring the widget, just close */
        this.finish();
        return;
    }

    /* Check for required permissions */
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this,
                    GmailContract.PERMISSION) != PackageManager.PERMISSION_GRANTED) {

        /* If the permissions aren't granted, ask for them */
        ActivityCompat.requestPermissions(this,
                new String[] { Manifest.permission.GET_ACCOUNTS, GmailContract.PERMISSION }, REQUEST_CODE);
        return;
    }

    /* All permissions granted, go get the list of accounts */
    getAccounts();
}

From source file:io.github.hidroh.materialistic.appwidget.WidgetConfigActivity.java

private void configure() {
    new WidgetHelper(this).configure(mAppWidgetId);
    setResult(RESULT_OK, new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId));
    finish();//from  w ww  .  ja  v  a 2s.co  m
}

From source file:com.ultrafunk.network_info.config.ConfigActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*/*from ww  w  .j av a 2 s . co m*/
    ToDo: So we can show the ConfigActivity when started from a lock screen widget
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    */

    // Set the result to CANCELED. This will cause the widget host to cancel out of the widget placement if they press the back button.
    setResult(RESULT_CANCELED);

    setContentView(R.layout.activity_config);

    // Find the widget id from the intent.
    Bundle extras = getIntent().getExtras();

    if (extras != null)
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);

    if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
        finish();

    appAppWidgetManager = AppWidgetManager.getInstance(this);

    widgetConfig = new WidgetConfig(this);
    widgetConfig.read(appWidgetId);

    // ToDo: Needs to change if/when the ConfigActivity is started from a widget or home screen
    widgetConfig.setBothWidgets(true);

    TextView configurationTextView = (TextView) findViewById(R.id.configurationTextView);
    configurationTextView.setText(
            (isLockscreenWidget(appAppWidgetManager, appWidgetId) ? getString(R.string.lockscreen_configuration)
                    : getString(R.string.homescreen_configuration)));

    initShowWidgetView();
    initMobileSettingsScreenView();
    initLockscreenGravityView();
    initTransparencyView();
    initOkAndCancelButtons();
}

From source file:com.concentriclivers.mms.com.android.mms.widget.MmsWidgetProvider.java

/**
 * Update the widget appWidgetId/*from  w w w .  j  a  v  a2s  . c  o m*/
 */
private static void updateWidget(Context context, int appWidgetId) {
    //        if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
    Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
    //        }
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    PendingIntent clickIntent;

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, MmsWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent);

    remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.app_label));

    // Open Mms's app conversation list when click on header
    final Intent convIntent = new Intent(context, ConversationList.class);
    clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent(context, ComposeMessageActivity.class);
    composeIntent.setAction(Intent.ACTION_SENDTO);
    clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ComposeMessageActivity.class);
    Intent msgIntent = new Intent(Intent.ACTION_VIEW);
    msgIntent.setType("vnd.android-dir/mms-sms");
    taskStackBuilder.addNextIntent(msgIntent);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
}