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:com.github.ajasmin.telususageandroidwidget.ReportAccountErrorActivity.java

private void retriveAppWidgetId() {
    Intent intent = getIntent();/* w  w  w  .j a  v a2  s  . c  om*/
    Bundle extras = intent.getExtras();
    appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
    if (extras != null) {
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    }

    // Finish the activity if we don't receive an appWidgetId
    if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
        finish();
}

From source file:com.android.gallery3d.gadget.WidgetConfigure.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        setResult(resultCode, new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId));
        finish();//  w  w  w  .  j  a v a  2 s .  c om
        return;
    }

    if (requestCode == REQUEST_WIDGET_TYPE) {
        setWidgetType(data);
    } else if (requestCode == REQUEST_CHOOSE_ALBUM) {
        setChoosenAlbum(data);
    } else if (requestCode == REQUEST_GET_PHOTO) {
        setChoosenPhoto(data);
    } else if (requestCode == REQUEST_CROP_IMAGE) {
        setPhotoWidget();
    } else {
        throw new AssertionError("unknown request: " + requestCode);
    }
}

From source file:ru.yandex.subtitles.ui.appwidget.AbstractAppWidget.java

private void startConversation(final Context context, final Intent intent) {
    final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    final String phrase = intent.getStringExtra(Intent.EXTRA_TEXT);

    if (TextUtilsExt.isEmpty(phrase)) {
        Analytics.onAppWidgetStartConversationClick();
    } else {//from  ww  w . ja  v a  2s. co m
        Analytics.onAppWidgetPhraseClick(phrase);
    }

    final Intent mainIntent = QuickStartActivity.createStartIntent(context);
    final Intent conversationIntent = ConversationActivity.createStartConversationIntent(context, appWidgetId,
            phrase);

    final TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addNextIntent(mainIntent);
    stackBuilder.addNextIntent(conversationIntent);
    stackBuilder.startActivities();
}

From source file:com.todotxt.todotxttouch.widget.ListWidgetProvider.java

private RemoteViews buildLayout(Context context, int appWidgetId, boolean showProgress) {
    RemoteViews rv;/*w ww.  j  a  va 2  s.c  om*/
    // Specify the service to provide data for the collection widget. Note
    // that we need to
    // embed the appWidgetId via the data otherwise it will be ignored.
    final Intent intent = new Intent(context, ListWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    rv = new RemoteViews(context.getPackageName(), R.layout.listwidget);
    rv.setRemoteAdapter(R.id.widget_list, intent);

    // Set the empty view to be displayed if the collection is empty. It
    // must be a sibling
    // view of the collection view.
    rv.setEmptyView(R.id.widget_list, R.id.empty_view);

    // Set click listener for the logo
    //        Intent clickIntent = new Intent(context, LoginScreen.class);
    //        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, clickIntent, 0);
    //        rv.setOnClickPendingIntent(R.id.listwidget_header, pendingIntent);

    // Set click listener for the 'add' button
    //        if (isAuthenticated(context)) {
    //            PendingIntent taskStackBuilderPendingIntent = TaskStackBuilder
    //                    .create(context)
    //                    .addNextIntent(new Intent(context, TodoTxtTouch.class))
    //                    .addNextIntent(new Intent(context, AddTask.class))
    //                    .getPendingIntent(0, 0);
    //            rv.setOnClickPendingIntent(R.id.listwidget_additem,
    //                    taskStackBuilderPendingIntent);
    //        } else {
    //            // if not logged in, just go to login screen
    //            rv.setOnClickPendingIntent(R.id.listwidget_additem, pendingIntent);
    //        }

    // Bind a click listener template for the contents of the list.
    // Note that we
    // need to update the intent's data if we set an extra, since the extras
    // will be
    // ignored otherwise.
    final Intent onClickIntent = new Intent(context, TodoTxtTouch.class);
    onClickIntent.setAction(ListWidgetProvider.ITEM_ACTION);
    onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent onClickPendingIntent = PendingIntent.getActivity(context, 0, onClickIntent, 0);
    rv.setPendingIntentTemplate(R.id.widget_list, onClickPendingIntent);

    // Bind the click intent for the refresh button on the widget
    final Intent refreshIntent = new Intent(context, ListWidgetProvider.class);
    refreshIntent.setAction(ListWidgetProvider.REFRESH_ACTION);
    refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0, refreshIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setOnClickPendingIntent(R.id.listwidget_refresh, refreshPendingIntent);

    if (showProgress) {
        rv.setViewVisibility(R.id.listwidget_progress, View.VISIBLE);
        rv.setViewVisibility(R.id.listwidget_refresh, View.INVISIBLE);
    } else {
        rv.setViewVisibility(R.id.listwidget_progress, View.INVISIBLE);
        rv.setViewVisibility(R.id.listwidget_refresh, View.VISIBLE);
    }

    return rv;
}

From source file:com.android.mail.widget.WidgetService.java

public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId,
        Account account, final int folderType, final int folderCapabilities, final Uri folderUri,
        final Uri folderConversationListUri, final String folderDisplayName, Class<?> serviceClass) {
    remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE);

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, serviceClass);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_TYPE, folderType);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CAPABILITIES, folderCapabilities);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_URI, folderUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CONVERSATION_LIST_URI, folderConversationListUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_DISPLAY_NAME, folderDisplayName);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(R.id.conversation_list, intent);
    // Open mail app when click on header
    final Intent mailIntent = Utils.createViewFolderIntent(context, folderUri, account);
    mailIntent.setPackage(context.getPackageName());
    PendingIntent clickIntent = PendingIntent.getActivity(context, 0, mailIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent();
    composeIntent.setPackage(context.getPackageName());
    composeIntent.setAction(Intent.ACTION_SEND);
    composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    composeIntent.setData(account.composeIntentUri);
    composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true);
    if (account.composeIntentUri != null) {
        composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri);
    }/*from   w w  w  . ja  v  a  2  s.c  o m*/

    // Build a task stack that forces the conversation list on the stack before the compose
    // activity.
    final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    clickIntent = taskStackBuilder.addNextIntent(mailIntent).addNextIntent(composeIntent).getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    final Intent conversationIntent = new Intent();
    conversationIntent.setPackage(context.getPackageName());
    conversationIntent.setAction(Intent.ACTION_VIEW);
    clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent);
}

From source file:au.com.wallaceit.reddinator.ViewRedditActivity.java

/**
 * (non-Javadoc)//from  w w  w.ja v  a 2  s .c  o m
 *
 * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
 */
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    global = ((GlobalObjects) ViewRedditActivity.this.getApplicationContext());
    prefs = PreferenceManager.getDefaultSharedPreferences(ViewRedditActivity.this);
    // set window flags
    getWindow().requestFeature(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    getWindow().requestFeature(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    // request loading bar first
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    // get actionbar and set home button, pad the icon
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    ImageView view = (ImageView) findViewById(android.R.id.home);
    if (view != null) {
        view.setPadding(5, 0, 5, 0);
    }
    // set content view
    setContentView(R.layout.viewreddit);
    // Setup TabHost
    initialiseTabHost(savedInstanceState);
    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); //set the tab as per the saved state
    }
    redditItemId = getIntent().getStringExtra(WidgetProvider.ITEM_ID);
    widgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0);
    feedposition = getIntent().getIntExtra("itemposition", 0);
    // Get selected item from feed and user vote preference
    JSONObject currentFeedItem = global.getFeedObject(prefs, widgetId, feedposition, redditItemId);
    try {
        userLikes = currentFeedItem.getString("likes");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    //System.out.println("User likes post: " + userLikes);
}

From source file:com.chen.mail.widget.WidgetService.java

public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId,
        Account account, final int folderType, final Uri folderUri, final Uri folderConversationListUri,
        final String folderDisplayName, Class<?> serviceClass) {
    remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE);

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, serviceClass);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_TYPE, folderType);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_URI, folderUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CONVERSATION_LIST_URI, folderConversationListUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_DISPLAY_NAME, folderDisplayName);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(R.id.conversation_list, intent);
    // Open mail app when click on header
    final Intent mailIntent = Utils.createViewFolderIntent(context, folderUri, account);
    PendingIntent clickIntent = PendingIntent.getActivity(context, 0, mailIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent();
    composeIntent.setAction(Intent.ACTION_SEND);
    composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    composeIntent.setData(account.composeIntentUri);
    composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true);
    if (account.composeIntentUri != null) {
        composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri);
    }//  w w w  .j  a  va2 s  . c  o m

    // Build a task stack that forces the conversation list on the stack before the compose
    // activity.
    final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    clickIntent = taskStackBuilder.addNextIntent(mailIntent).addNextIntent(composeIntent).getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    final Intent conversationIntent = new Intent();
    conversationIntent.setAction(Intent.ACTION_VIEW);
    clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent);
}

From source file:au.com.wallaceit.reddinator.ViewRedditActivity.java

/**
 * (non-Javadoc)/*from  w w w  .j  a v a2s.co m*/
 *
 * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
 */
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    global = ((GlobalObjects) ViewRedditActivity.this.getApplicationContext());
    prefs = PreferenceManager.getDefaultSharedPreferences(ViewRedditActivity.this);
    global.loadSavedAccn(prefs);
    // set window flags
    getWindow().requestFeature(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    getWindow().requestFeature(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    // request loading bar first
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    // get actionbar and set home button, pad the icon
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    ImageView view = (ImageView) findViewById(android.R.id.home);
    if (view != null) {
        view.setPadding(5, 0, 5, 0);
    }
    // set content view
    setContentView(R.layout.viewreddit);
    // Setup TabHost
    initialiseTabHost(savedInstanceState);
    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); //set the tab as per the saved state
    }
    redditItemId = getIntent().getStringExtra(WidgetProvider.ITEM_ID);
    widgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0);
    feedposition = getIntent().getIntExtra("itemposition", 0);
    // Get selected item from feed and user vote preference
    JSONObject currentFeedItem = global.getFeedObject(prefs, widgetId, feedposition, redditItemId);
    try {
        userLikes = currentFeedItem.getString("likes");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    System.out.println("User likes post: " + userLikes);
}

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

private void closeActivity() {
    Context context = MainActivity.this;
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ThermoWidget.remakeWidget(context, appWidgetManager, appWidgetId);
    Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    setResult(RESULT_OK, resultValue);/*from  ww  w  . ja  v a2 s .c o  m*/
    finish();
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.widget.ListWidgetConfig.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_widget_config);

    setResult(RESULT_CANCELED);/*from  ww w  .  ja  v a2s  .co m*/

    Intent intent = getIntent();
    if (intent != null && intent.getExtras() != null) {
        appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
    } else {
        appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
        Log.d(TAG, "Invalid ID given in the intent");
        Intent resultValue = new Intent();
        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        setResult(RESULT_CANCELED, resultValue);
        finish();
    }

    setupPreview();
    setupActionBar();
    setupConfig();
}