List of usage examples for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID
String EXTRA_APPWIDGET_ID
To view the source code for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID.
Click Source Link
From source file:com.launcher.silverfish.launcher.homescreen.HomeScreenFragment.java
private void loadWidget() { ComponentName cn = settings.getWidget(); Log.d("Widget creation", "Loaded from db: " + cn.getClassName() + " - " + cn.getPackageName()); // Check that there actually is a widget in the database if (cn.getPackageName().isEmpty() && cn.getClassName().isEmpty()) { Log.d("Widget creation", "DB was empty"); return;/*from w ww .j a va 2 s .c om*/ } Log.d("Widget creation", "DB was not empty"); final List<AppWidgetProviderInfo> infos = mAppWidgetManager.getInstalledProviders(); // Get AppWidgetProviderInfo AppWidgetProviderInfo appWidgetInfo = null; // Just in case you want to see all package and class names of installed widget providers, // this code is useful for (final AppWidgetProviderInfo info : infos) { Log.d("AD3", info.provider.getPackageName() + " / " + info.provider.getClassName()); } // Iterate through all infos, trying to find the desired one for (final AppWidgetProviderInfo info : infos) { if (info.provider.getClassName().equals(cn.getClassName()) && info.provider.getPackageName().equals(cn.getPackageName())) { // We found it! appWidgetInfo = info; break; } } if (appWidgetInfo == null) { Log.d("Widget creation", "app info was null"); return; // Stop here } // Allocate the hosted widget id int appWidgetId = mAppWidgetHost.allocateAppWidgetId(); boolean allowed_to_bind = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn); // Ask the user to allow this app to have access to their widgets if (!allowed_to_bind) { Log.d("Widget creation", "asking for permission"); Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); Bundle args = new Bundle(); args.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, cn); if (Build.VERSION.SDK_INT >= 21) { args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE, null); } i.putExtras(args); startActivityForResult(i, REQUEST_BIND_APPWIDGET); return; } else { Log.d("Widget creation", "Allowed to bind"); Log.d("Widget creation", "creating widget"); //Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); //createWidgetFromId(appWidgetId); } // Create the host view AppWidgetHostView hostView = mAppWidgetHost.createView(getActivity().getBaseContext(), appWidgetId, appWidgetInfo); // Set the desired widget hostView.setAppWidget(appWidgetId, appWidgetInfo); placeWidget(hostView); }
From source file:org.durka.hallmonitor.CoreStateManager.java
public void createWidget(String widgetType) { int widgetId = preference_all.getInt(widgetType + "_widget_id", -1); if (widgetId != -1) { if (!hmAppWidgetManager.doesWidgetExist(widgetType)) { Log.d(LOG_TAG, "creating " + widgetType + " widget with id=" + widgetId); Intent data = new Intent(); data.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId); hmAppWidgetManager.createWidget(widgetType, data); }//w ww.j av a2 s. c o m } }
From source file:com.shafiq.myfeedle.core.StatusDialog.java
@Override public void onClick(final DialogInterface dialog, int which) { switch (which) { case COMMENT: if (mAppWidgetId != -1) { if (mService == GOOGLEPLUS) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://plus.google.com"))); else if (mService == PINTEREST) { if (mSid != null) startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(PINTEREST_PIN, mSid)))); else startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); } else startActivity(Myfeedle.getPackageIntent(this, MyfeedleComments.class).setData(mData)); } else// w w w .j ava 2 s . c o m (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); break; case POST: if (mAppWidgetId != -1) { if (mService == GOOGLEPLUS) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://plus.google.com"))); else if (mService == PINTEREST) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); else startActivity(Myfeedle.getPackageIntent(this, MyfeedleCreatePost.class).setData(Uri .withAppendedPath(Accounts.getContentUri(StatusDialog.this), Long.toString(mAccount)))); dialog.cancel(); finish(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // no account, dialog to select one // don't limit accounts to the widget Cursor c = StatusDialog.this.getContentResolver().query( Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, ACCOUNTS_QUERY }, null, null, null); if (c.moveToFirst()) { int iid = c.getColumnIndex(Accounts._ID), iusername = c.getColumnIndex(Accounts.USERNAME), i = 0; final long[] accountIndexes = new long[c.getCount()]; final String[] accounts = new String[c.getCount()]; while (!c.isAfterLast()) { long id = c.getLong(iid); accountIndexes[i] = id; accounts[i++] = c.getString(iusername); c.moveToNext(); } arg0.cancel(); mDialog = (new AlertDialog.Builder(StatusDialog.this)).setTitle(R.string.accounts) .setSingleChoiceItems(accounts, -1, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { startActivity(Myfeedle .getPackageIntent(StatusDialog.this, MyfeedleCreatePost.class) .setData(Uri.withAppendedPath( Accounts.getContentUri(StatusDialog.this), Long.toString(accountIndexes[which])))); arg0.cancel(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); } }).create(); mDialog.show(); } else { (Toast.makeText(StatusDialog.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); } c.close(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); } } break; case SETTINGS: if (mAppWidgetId != -1) { startActivity(Myfeedle.getPackageIntent(this, ManageAccounts.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId)); dialog.cancel(); finish(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { startActivity(Myfeedle.getPackageIntent(StatusDialog.this, ManageAccounts.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetIds[arg1])); arg0.cancel(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); } } break; case NOTIFICATIONS: startActivity(Myfeedle.getPackageIntent(this, MyfeedleNotifications.class)); dialog.cancel(); finish(); break; case REFRESH: if (mAppWidgetId != -1) { (Toast.makeText(getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Myfeedle.getPackageIntent(this, MyfeedleService.class).setAction(ACTION_REFRESH) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetId })); dialog.cancel(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { (Toast.makeText(StatusDialog.this.getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Myfeedle.getPackageIntent(StatusDialog.this, MyfeedleService.class) .setAction(ACTION_REFRESH).putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetIds[arg1] })); arg0.cancel(); finish(); } }).setPositiveButton(R.string.refreshallwidgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { // refresh all (Toast.makeText(StatusDialog.this.getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Myfeedle.getPackageIntent(StatusDialog.this, MyfeedleService.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, mAppWidgetIds)); arg0.cancel(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { dialog.cancel(); finish(); } } break; case PROFILE: Cursor account; final AsyncTask<String, Void, String> asyncTask; // get the resources switch (mService) { case TWITTER: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET, arg0[0], arg0[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest( new HttpGet(String.format(TWITTER_USER, TWITTER_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject user = new JSONObject(response); startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri .parse(String.format(TWITTER_PROFILE, user.getString("screen_name"))))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case FACEBOOK: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), new HttpGet(String.format(FACEBOOK_USER, FACEBOOK_BASE_URL, mEsid, Saccess_token, arg0[0]))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse((new JSONObject(response)).getString("link")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))); } account.close(); break; case MYSPACE: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(MYSPACE_KEY, MYSPACE_SECRET, arg0[0], arg0[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest( new HttpGet(String.format(MYSPACE_USER, MYSPACE_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse((new JSONObject(response)).getJSONObject("person") .getString("profileUrl")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case FOURSQUARE: startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(FOURSQUARE_URL_PROFILE, mEsid)))); finish(); break; case LINKEDIN: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(LINKEDIN_KEY, LINKEDIN_SECRET, arg0[0], arg0[1]); HttpGet httpGet = new HttpGet(String.format(LINKEDIN_URL_USER, mEsid)); for (String[] header : LINKEDIN_HEADERS) httpGet.setHeader(header[0], header[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest(httpGet)); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( (new JSONObject(response)).getJSONObject("siteStandardProfileRequest") .getString("url").replaceAll("\\\\", "")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case IDENTICA: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(IDENTICA_KEY, IDENTICA_SECRET, arg0[0], arg0[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest( new HttpGet(String.format(IDENTICA_USER, IDENTICA_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject user = new JSONObject(response); startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( String.format(IDENTICA_PROFILE, user.getString("screen_name"))))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case GOOGLEPLUS: startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(GOOGLEPLUS_PROFILE, mEsid)))); finish(); break; case PINTEREST: if (mEsid != null) startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(PINTEREST_PROFILE, mEsid)))); else startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); finish(); break; case CHATTER: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { // need to get an instance return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), new HttpPost(String.format(CHATTER_URL_ACCESS, CHATTER_KEY, arg0[0]))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject jobj = new JSONObject(response); if (jobj.has("instance_url")) { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(jobj.getString("instance_url") + "/" + mEsid))); } } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))); } account.close(); break; } break; default: if ((itemsData != null) && (which < itemsData.length) && (itemsData[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(itemsData[which]))); else (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); finish(); break; } }
From source file:com.launcher.silverfish.HomeScreenFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // listen for widget manager response if (resultCode == Activity.RESULT_OK) { if (requestCode == REQUEST_PICK_APPWIDGET) { configureWidget(data);//from w ww .j a v a2 s .c o m } else if (requestCode == REQUEST_CREATE_APPWIDGET) { createWidget(data); } else if (requestCode == REQUEST_BIND_APPWIDGET) { createWidget(data); } } else if (resultCode == Activity.RESULT_CANCELED && data != null) { int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); if (appWidgetId != -1) { mAppWidgetHost.deleteAppWidgetId(appWidgetId); } } }
From source file:com.android.leanlauncher.LauncherTransitionable.java
private void handleActivityResult(final int requestCode, final int resultCode, final Intent data) { // Reset the startActivity waiting flag setWaitingForResult(false);//ww w . j a v a2 s. c o m final int pendingAddWidgetId = mPendingAddWidgetId; mPendingAddWidgetId = -1; if (requestCode == REQUEST_BIND_APPWIDGET) { final int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; if (resultCode == RESULT_CANCELED) { completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); } else if (resultCode == RESULT_OK) { addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY); } return; } else if (requestCode == REQUEST_PICK_WALLPAPER) { if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) { mWorkspace.exitOverviewMode(false); } return; } boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || requestCode == REQUEST_CREATE_APPWIDGET); final boolean workspaceLocked = isWorkspaceLocked(); // We have special handling for widgets if (isWidgetDrop) { final int appWidgetId; int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; if (widgetId < 0) { appWidgetId = pendingAddWidgetId; } else { appWidgetId = widgetId; } final int result; if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + "returned from the widget configuration activity."); result = RESULT_CANCELED; completeTwoStageWidgetDrop(result, appWidgetId); final Runnable onComplete = new Runnable() { @Override public void run() { exitSpringLoadedDragModeDelayed(false, 0, null); } }; if (workspaceLocked) { // No need to remove the empty screen if we're mid-binding, as the // the bind will not add the empty screen. mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY); } } else { if (!workspaceLocked) { completeTwoStageWidgetDrop(resultCode, appWidgetId); } else { sPendingAddItem = preparePendingAddArgs(requestCode, data, appWidgetId, mPendingAddInfo); } } return; } if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) { if (resultCode == RESULT_OK) { // Update the widget view. PendingAddArguments args = preparePendingAddArgs(requestCode, data, pendingAddWidgetId, mPendingAddInfo); if (workspaceLocked) { sPendingAddItem = args; } else { completeAdd(args); } } // Leave the widget in the pending state if the user canceled the configure. return; } // The pattern used here is that a user PICKs a specific application, // which, depending on the target, might need to CREATE the actual target. // For example, the user would PICK_SHORTCUT for "Music playlist", and we // launch over to the Music app to actually CREATE_SHORTCUT. if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1, mPendingAddInfo); if (isWorkspaceLocked()) { sPendingAddItem = args; } else { completeAdd(args); } } mDragLayer.clearAnimatedView(); }
From source file:com.android.messaging.ui.UIIntentsImpl.java
@Override public PendingIntent getWidgetPendingIntentForConfigurationActivity(final Context context, final int appWidgetId) { final Intent configureIntent = new Intent(context, WidgetPickConversationActivity.class); configureIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); configureIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); configureIntent.setData(Uri.parse(configureIntent.toUri(Intent.URI_INTENT_SCHEME))); configureIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY); return getPendingIntentWithParentStack(context, configureIntent, 0); }
From source file:com.android.launcher2.Launcher.java
/** * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have * a configuration step, this allows the proper animations to run after other transitions. *///from w w w .j a v a 2 s . co m private boolean completeAdd(PendingAddArguments args) { boolean result = false; switch (args.requestCode) { case REQUEST_PICK_APPLICATION: completeAddApplication(args.intent, args.container, args.screen, args.cellX, args.cellY); break; case REQUEST_PICK_SHORTCUT: processShortcut(args.intent); break; case REQUEST_CREATE_SHORTCUT: completeAddShortcut(args.intent, args.container, args.screen, args.cellX, args.cellY); result = true; break; case REQUEST_CREATE_APPWIDGET: int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); completeAddAppWidget(appWidgetId, args.container, args.screen, null, null); result = true; break; case REQUEST_PICK_WALLPAPER: // We just wanted the activity result here so we can clear mWaitingForResult break; } // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, // if you turned the screen off and then back while in All Apps, Launcher would not // return to the workspace. Clearing mAddInfo.container here fixes this issue resetAddInfo(); return result; }
From source file:com.android.launcher2.Launcher.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (requestCode == REQUEST_BIND_APPWIDGET) { int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; if (resultCode == RESULT_CANCELED) { completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); } else if (resultCode == RESULT_OK) { addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo); }//from w w w. ja v a 2s . c o m return; } boolean delayExitSpringLoadedMode = false; boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || requestCode == REQUEST_CREATE_APPWIDGET); mWaitingForResult = false; // We have special handling for widgets if (isWidgetDrop) { int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; if (appWidgetId < 0) { Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" + "widget configuration activity."); completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); } else { completeTwoStageWidgetDrop(resultCode, appWidgetId); } return; } // The pattern used here is that a user PICKs a specific application, // which, depending on the target, might need to CREATE the actual target. // For example, the user would PICK_SHORTCUT for "Music playlist", and we // launch over to the Music app to actually CREATE_SHORTCUT. if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { final PendingAddArguments args = new PendingAddArguments(); args.requestCode = requestCode; args.intent = data; args.container = mPendingAddInfo.container; args.screen = mPendingAddInfo.screen; args.cellX = mPendingAddInfo.cellX; args.cellY = mPendingAddInfo.cellY; if (isWorkspaceLocked()) { sPendingAddList.add(args); } else { delayExitSpringLoadedMode = completeAdd(args); } } mDragLayer.clearAnimatedView(); // Exit spring loaded mode if necessary after cancelling the configuration of a widget exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode, null); }
From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (DrawerConfiguration.USE_GX_SWITCHES_WIDGETS) { if (requestCode == REQUEST_DRAWER_BIND_APPWIDGET) { int appWidgetId = (data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1); if (resultCode == RESULT_OK) { ((LauncherDrawerLayout) this.drawerLayout).implementSwitchWidget(appWidgetId); //addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo); } // else do nothing... should put alert or error msg? return; }// w w w . j a va 2 s . com if (requestCode == REQUEST_DRAWER_CREATE_APPWIDGET) { int appWidgetId = (data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1); if (resultCode == RESULT_OK && appWidgetId != -1) { ((LauncherDrawerLayout) this.drawerLayout).completeSwitchWidget(appWidgetId); } else { // cancel, delete widget ID mAppWidgetHost.deleteAppWidgetId(appWidgetId); } return; } if (requestCode == REQUEST_DRAWER_SETTINGS_DONE) { ((LauncherDrawerLayout) this.drawerLayout).refreshSwitches(); } } if (requestCode == REQUEST_BIND_APPWIDGET) { int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; if (resultCode == RESULT_CANCELED) { completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); } else if (resultCode == RESULT_OK) { addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo); } return; } boolean delayExitSpringLoadedMode = false; boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || requestCode == REQUEST_CREATE_APPWIDGET); mWaitingForResult = false; // We have special handling for widgets if (isWidgetDrop) { int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; if (appWidgetId < 0) { Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" + "widget configuration activity."); completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); } else { completeTwoStageWidgetDrop(resultCode, appWidgetId); } return; } // The pattern used here is that a user PICKs a specific application, // which, depending on the target, might need to CREATE the actual target. // For example, the user would PICK_SHORTCUT for "Music playlist", and we // launch over to the Music app to actually CREATE_SHORTCUT. if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { final PendingAddArguments args = new PendingAddArguments(); args.requestCode = requestCode; args.intent = data; args.container = mPendingAddInfo.container; args.screen = mPendingAddInfo.screen; args.cellX = mPendingAddInfo.cellX; args.cellY = mPendingAddInfo.cellY; if (isWorkspaceLocked()) { sPendingAddList.add(args); } else { delayExitSpringLoadedMode = completeAdd(args); } } mDragLayer.clearAnimatedView(); // Exit spring loaded mode if necessary after cancelling the configuration of a widget exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode, null); }
From source file:de.spiritcroc.modular_remote.MainActivity.java
public void addWidget(Container container) { addWidgetContainer = container;/*from w w w . ja v a 2 s . c o m*/ int appWidgetId = appWidgetHost.allocateAppWidgetId(); Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); startActivityForResult(pickIntent, MainActivity.REQUEST_PICK_APPWIDGET); }