Last active
November 6, 2017 07:42
-
-
Save yerenutku/101c87a7fdcbcab030686013564b3ece 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); | |
// 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
add
btAdd=(Button)findViewById(R.id.btAdd);
at line 15 to avoid Null Pointer Error