Forked from yerenutku/ConfigurableWidgetConfigureActivity.java
Last active
November 6, 2017 07:42
-
-
Save gotoark/cc6f6b5615b656930c874ed05943d0c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConfigurableWidgetConfigureActivity extends Activity { | |
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; | |
private EditText etUrl; | |
private Button btAdd; | |
private AppWidgetManager widgetManager; | |
private RemoteViews views; | |
@Override | |
public void onCreate(Bundle icicle) { | |
super.onCreate(icicle); | |
setResult(RESULT_CANCELED); | |
// activity stuffs | |
setContentView(R.layout.activity_widget_configure); | |
etUrl = (EditText) findViewById(R.id.etUrl); | |
btAdd=(Button)findViewById(R.id.btAdd); | |
// These steps are seen in the previous examples | |
widgetManager = AppWidgetManager.getInstance(this); | |
views = new RemoteViews(this.getPackageName(), R.layout.configurable_widget); | |
// Find the widget id from the intent. | |
Intent intent = getIntent(); | |
Bundle extras = intent.getExtras(); | |
if (extras != null) { | |
mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); | |
} | |
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { | |
finish(); | |
return; | |
} | |
btAdd.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
// Gets user input | |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(etUrl.getText().toString())); | |
PendingIntent pending = PendingIntent.getActivity(ConfigurableWidgetConfigureActivity.this, 0, intent, 0); | |
views.setOnClickPendingIntent(R.id.ivWidget, pending); | |
widgetManager.updateAppWidget(mAppWidgetId, views); | |
Intent resultValue = new Intent(); | |
// Set the results as expected from a 'configure activity'. | |
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); | |
setResult(RESULT_OK, resultValue); | |
finish(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment