List of usage examples for android.appwidget AppWidgetManager INVALID_APPWIDGET_ID
int INVALID_APPWIDGET_ID
To view the source code for android.appwidget AppWidgetManager INVALID_APPWIDGET_ID.
Click Source Link
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);// ww w . j ava2s .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(); }
From source file:com.piusvelte.sonet.OAuthLogin.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);//from w ww. j a v a 2s . c o m mHttpClient = SonetHttpClient.getThreadSafeClient(getApplicationContext()); mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(getString(R.string.loading)); mLoadingDialog.setCancelable(true); mLoadingDialog.setOnCancelListener(this); mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this); Intent intent = getIntent(); if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { int service = extras.getInt(Sonet.Accounts.SERVICE, Sonet.INVALID_SERVICE); mServiceName = Sonet.getServiceName(getResources(), service); mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); mAccountId = extras.getLong(Sonet.EXTRA_ACCOUNT_ID, Sonet.INVALID_ACCOUNT_ID); mSonetWebView = new SonetWebView(); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... args) { try { return mSonetOAuth.getAuthUrl(args[0], args[1], args[2], args[3], Boolean.parseBoolean(args[4]), mHttpClient); } catch (OAuthMessageSignerException e) { e.printStackTrace(); } catch (OAuthNotAuthorizedException e) { e.printStackTrace(); } catch (OAuthExpectationFailedException e) { e.printStackTrace(); } catch (OAuthCommunicationException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String url) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); // load the webview if (url != null) { mSonetWebView.open(url); } else { (Toast.makeText(OAuthLogin.this, String.format(getString(R.string.oauth_error), mServiceName), Toast.LENGTH_LONG)).show(); OAuthLogin.this.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); dialog.cancel(); OAuthLogin.this.finish(); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); dialog.cancel(); OAuthLogin.this.finish(); } }); switch (service) { case TWITTER: mSonetOAuth = new SonetOAuth(BuildConfig.TWITTER_KEY, BuildConfig.TWITTER_SECRET); asyncTask.execute(String.format(TWITTER_URL_REQUEST, TWITTER_BASE_URL), String.format(TWITTER_URL_ACCESS, TWITTER_BASE_URL), String.format(TWITTER_URL_AUTHORIZE, TWITTER_BASE_URL), TWITTER_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FACEBOOK: mSonetWebView.open(String.format(FACEBOOK_URL_AUTHORIZE, FACEBOOK_BASE_URL, BuildConfig.FACEBOOK_ID, FACEBOOK_CALLBACK.toString())); break; case MYSPACE: mSonetOAuth = new SonetOAuth(BuildConfig.MYSPACE_KEY, BuildConfig.MYSPACE_SECRET); asyncTask.execute(MYSPACE_URL_REQUEST, MYSPACE_URL_ACCESS, MYSPACE_URL_AUTHORIZE, MYSPACE_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FOURSQUARE: mSonetWebView.open(String.format(FOURSQUARE_URL_AUTHORIZE, BuildConfig.FOURSQUARE_KEY, FOURSQUARE_CALLBACK.toString())); break; case LINKEDIN: mSonetOAuth = new SonetOAuth(BuildConfig.LINKEDIN_KEY, BuildConfig.LINKEDIN_SECRET); asyncTask.execute(LINKEDIN_URL_REQUEST, LINKEDIN_URL_ACCESS, LINKEDIN_URL_AUTHORIZE, LINKEDIN_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case SMS: Cursor c = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); if (c.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "SMS has already been added.", Toast.LENGTH_LONG)).show(); } else { addAccount(getResources().getStringArray(R.array.service_entries)[SMS], null, null, 0, SMS, null); } c.close(); finish(); break; case RSS: // prompt for RSS url final EditText rss_url = new EditText(this); rss_url.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this).setTitle(R.string.rss_url).setView(rss_url) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { // test the url and add if valid, else Toast error mLoadingDialog.show(); (new AsyncTask<String, Void, String>() { String url; @Override protected String doInBackground(String... params) { url = rss_url.getText().toString(); return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(url)); } @Override protected void onPostExecute(String response) { mLoadingDialog.dismiss(); if (response != null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(response)); Document doc = db.parse(is); // test parsing... NodeList nodes = doc.getElementsByTagName(Sitem); if (nodes.getLength() > 0) { // check for an image NodeList images = doc.getElementsByTagName(Simage); if (images.getLength() > 0) { NodeList imageChildren = images.item(0).getChildNodes(); Node n = imageChildren.item(0); if (n.getNodeName().toLowerCase().equals(Surl)) { if (n.hasChildNodes()) { n.getChildNodes().item(0).getNodeValue(); } } } NodeList children = nodes.item(0).getChildNodes(); String date = null; String title = null; String description = null; String link = null; int values_count = 0; for (int child = 0, c2 = children.getLength(); (child < c2) && (values_count < 4); child++) { Node n = children.item(child); if (n.getNodeName().toLowerCase().equals(Spubdate)) { values_count++; if (n.hasChildNodes()) { date = n.getChildNodes().item(0).getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Stitle)) { values_count++; if (n.hasChildNodes()) { title = n.getChildNodes().item(0) .getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Sdescription)) { values_count++; if (n.hasChildNodes()) { StringBuilder sb = new StringBuilder(); NodeList descNodes = n.getChildNodes(); for (int dn = 0, dn2 = descNodes .getLength(); dn < dn2; dn++) { Node descNode = descNodes.item(dn); if (descNode .getNodeType() == Node.TEXT_NODE) { sb.append(descNode.getNodeValue()); } } // strip out the html tags description = sb.toString() .replaceAll("\\<(.|\n)*?>", ""); } } else if (n.getNodeName().toLowerCase() .equals(Slink)) { values_count++; if (n.hasChildNodes()) { link = n.getChildNodes().item(0).getNodeValue(); } } } if (Sonet.HasValues( new String[] { title, description, link, date })) { final EditText url_name = new EditText(OAuthLogin.this); url_name.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this) .setTitle(R.string.rss_channel) .setView(url_name) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { addAccount( url_name.getText() .toString(), null, null, 0, RSS, url); dialog1.dismiss(); dialog.dismiss(); finish(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { dialog1.dismiss(); dialog.dismiss(); finish(); } }) .show(); } else { (Toast.makeText(OAuthLogin.this, "Feed is missing standard fields", Toast.LENGTH_LONG)).show(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } catch (ParserConfigurationException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (SAXException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (IOException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid URL", Toast.LENGTH_LONG)) .show(); dialog.dismiss(); finish(); } } }).execute(rss_url.getText().toString()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }).show(); break; case IDENTICA: mSonetOAuth = new SonetOAuth(BuildConfig.IDENTICA_KEY, BuildConfig.IDENTICA_SECRET); asyncTask.execute(String.format(IDENTICA_URL_REQUEST, IDENTICA_BASE_URL), String.format(IDENTICA_URL_ACCESS, IDENTICA_BASE_URL), String.format(IDENTICA_URL_AUTHORIZE, IDENTICA_BASE_URL), IDENTICA_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case GOOGLEPLUS: mSonetWebView.open(String.format(GOOGLEPLUS_AUTHORIZE, BuildConfig.GOOGLECLIENT_ID, "urn:ietf:wg:oauth:2.0:oob")); break; case CHATTER: mSonetWebView.open(String.format(CHATTER_URL_AUTHORIZE, BuildConfig.CHATTER_KEY, CHATTER_CALLBACK.toString())); break; case PINTEREST: Cursor pinterestAccount = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(PINTEREST) }, null); if (pinterestAccount.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "Pinterest has already been added.", Toast.LENGTH_LONG)) .show(); } else { (Toast.makeText(OAuthLogin.this, "Pinterest currently allows only public, non-authenticated viewing.", Toast.LENGTH_LONG)).show(); String[] values = getResources().getStringArray(R.array.service_values); String[] entries = getResources().getStringArray(R.array.service_entries); for (int i = 0, l = values.length; i < l; i++) { if (Integer.toString(PINTEREST).equals(values[i])) { addAccount(entries[i], null, null, 0, PINTEREST, null); break; } } } pinterestAccount.close(); finish(); break; default: this.finish(); } } } }
From source file:com.piusvelte.sonet.core.OAuthLogin.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);/*from ww w. ja va2s. c o m*/ mHttpClient = SonetHttpClient.getThreadSafeClient(getApplicationContext()); mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(getString(R.string.loading)); mLoadingDialog.setCancelable(true); mLoadingDialog.setOnCancelListener(this); mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this); Intent intent = getIntent(); if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { int service = extras.getInt(Sonet.Accounts.SERVICE, Sonet.INVALID_SERVICE); mServiceName = Sonet.getServiceName(getResources(), service); mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); mAccountId = extras.getLong(Sonet.EXTRA_ACCOUNT_ID, Sonet.INVALID_ACCOUNT_ID); mSonetWebView = new SonetWebView(); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... args) { try { return mSonetOAuth.getAuthUrl(args[0], args[1], args[2], args[3], Boolean.parseBoolean(args[4]), mHttpClient); } catch (OAuthMessageSignerException e) { e.printStackTrace(); } catch (OAuthNotAuthorizedException e) { e.printStackTrace(); } catch (OAuthExpectationFailedException e) { e.printStackTrace(); } catch (OAuthCommunicationException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String url) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); // load the webview if (url != null) { mSonetWebView.open(url); } else { (Toast.makeText(OAuthLogin.this, String.format(getString(R.string.oauth_error), mServiceName), Toast.LENGTH_LONG)).show(); OAuthLogin.this.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); dialog.cancel(); OAuthLogin.this.finish(); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); dialog.cancel(); OAuthLogin.this.finish(); } }); switch (service) { case TWITTER: mSonetOAuth = new SonetOAuth(TWITTER_KEY, TWITTER_SECRET); asyncTask.execute(String.format(TWITTER_URL_REQUEST, TWITTER_BASE_URL), String.format(TWITTER_URL_ACCESS, TWITTER_BASE_URL), String.format(TWITTER_URL_AUTHORIZE, TWITTER_BASE_URL), TWITTER_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FACEBOOK: mSonetWebView.open(String.format(FACEBOOK_URL_AUTHORIZE, FACEBOOK_BASE_URL, FACEBOOK_ID, FACEBOOK_CALLBACK.toString())); break; case MYSPACE: mSonetOAuth = new SonetOAuth(MYSPACE_KEY, MYSPACE_SECRET); asyncTask.execute(MYSPACE_URL_REQUEST, MYSPACE_URL_ACCESS, MYSPACE_URL_AUTHORIZE, MYSPACE_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FOURSQUARE: mSonetWebView.open(String.format(FOURSQUARE_URL_AUTHORIZE, FOURSQUARE_KEY, FOURSQUARE_CALLBACK.toString())); break; case LINKEDIN: mSonetOAuth = new SonetOAuth(LINKEDIN_KEY, LINKEDIN_SECRET); asyncTask.execute(LINKEDIN_URL_REQUEST, LINKEDIN_URL_ACCESS, LINKEDIN_URL_AUTHORIZE, LINKEDIN_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case SMS: Cursor c = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); if (c.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "SMS has already been added.", Toast.LENGTH_LONG)).show(); } else { addAccount(getResources().getStringArray(R.array.service_entries)[SMS], null, null, 0, SMS, null); } c.close(); finish(); break; case RSS: // prompt for RSS url final EditText rss_url = new EditText(this); rss_url.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this).setTitle(R.string.rss_url).setView(rss_url) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { // test the url and add if valid, else Toast error mLoadingDialog.show(); (new AsyncTask<String, Void, String>() { String url; @Override protected String doInBackground(String... params) { url = rss_url.getText().toString(); return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(url)); } @Override protected void onPostExecute(String response) { mLoadingDialog.dismiss(); if (response != null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(response)); Document doc = db.parse(is); // test parsing... NodeList nodes = doc.getElementsByTagName(Sitem); if (nodes.getLength() > 0) { // check for an image NodeList images = doc.getElementsByTagName(Simage); if (images.getLength() > 0) { NodeList imageChildren = images.item(0).getChildNodes(); Node n = imageChildren.item(0); if (n.getNodeName().toLowerCase().equals(Surl)) { if (n.hasChildNodes()) { n.getChildNodes().item(0).getNodeValue(); } } } NodeList children = nodes.item(0).getChildNodes(); String date = null; String title = null; String description = null; String link = null; int values_count = 0; for (int child = 0, c2 = children.getLength(); (child < c2) && (values_count < 4); child++) { Node n = children.item(child); if (n.getNodeName().toLowerCase().equals(Spubdate)) { values_count++; if (n.hasChildNodes()) { date = n.getChildNodes().item(0).getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Stitle)) { values_count++; if (n.hasChildNodes()) { title = n.getChildNodes().item(0) .getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Sdescription)) { values_count++; if (n.hasChildNodes()) { StringBuilder sb = new StringBuilder(); NodeList descNodes = n.getChildNodes(); for (int dn = 0, dn2 = descNodes .getLength(); dn < dn2; dn++) { Node descNode = descNodes.item(dn); if (descNode .getNodeType() == Node.TEXT_NODE) { sb.append(descNode.getNodeValue()); } } // strip out the html tags description = sb.toString() .replaceAll("\\<(.|\n)*?>", ""); } } else if (n.getNodeName().toLowerCase() .equals(Slink)) { values_count++; if (n.hasChildNodes()) { link = n.getChildNodes().item(0).getNodeValue(); } } } if (Sonet.HasValues( new String[] { title, description, link, date })) { final EditText url_name = new EditText(OAuthLogin.this); url_name.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this) .setTitle(R.string.rss_channel) .setView(url_name) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { addAccount( url_name.getText() .toString(), null, null, 0, RSS, url); dialog1.dismiss(); dialog.dismiss(); finish(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { dialog1.dismiss(); dialog.dismiss(); finish(); } }) .show(); } else { (Toast.makeText(OAuthLogin.this, "Feed is missing standard fields", Toast.LENGTH_LONG)).show(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } catch (ParserConfigurationException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (SAXException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (IOException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid URL", Toast.LENGTH_LONG)) .show(); dialog.dismiss(); finish(); } } }).execute(rss_url.getText().toString()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }).show(); break; case IDENTICA: mSonetOAuth = new SonetOAuth(IDENTICA_KEY, IDENTICA_SECRET); asyncTask.execute(String.format(IDENTICA_URL_REQUEST, IDENTICA_BASE_URL), String.format(IDENTICA_URL_ACCESS, IDENTICA_BASE_URL), String.format(IDENTICA_URL_AUTHORIZE, IDENTICA_BASE_URL), IDENTICA_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case GOOGLEPLUS: mSonetWebView.open( String.format(GOOGLEPLUS_AUTHORIZE, GOOGLE_CLIENTID, "urn:ietf:wg:oauth:2.0:oob")); break; case CHATTER: mSonetWebView .open(String.format(CHATTER_URL_AUTHORIZE, CHATTER_KEY, CHATTER_CALLBACK.toString())); break; case PINTEREST: Cursor pinterestAccount = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(PINTEREST) }, null); if (pinterestAccount.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "Pinterest has already been added.", Toast.LENGTH_LONG)) .show(); } else { (Toast.makeText(OAuthLogin.this, "Pinterest currently allows only public, non-authenticated viewing.", Toast.LENGTH_LONG)).show(); String[] values = getResources().getStringArray(R.array.service_values); String[] entries = getResources().getStringArray(R.array.service_entries); for (int i = 0, l = values.length; i < l; i++) { if (Integer.toString(PINTEREST).equals(values[i])) { addAccount(entries[i], null, null, 0, PINTEREST, null); break; } } } pinterestAccount.close(); finish(); break; default: this.finish(); } } } }
From source file:org.gnucash.android.ui.homescreen.WidgetConfigurationActivity.java
/** * Sets click listeners for the buttons in the dialog *//*from w w w . ja v a 2 s . com*/ private void bindListeners() { mBooksSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Book book = BooksDbAdapter.getInstance().getRecord(id); SQLiteDatabase db = new DatabaseHelper(WidgetConfigurationActivity.this, book.getUID()) .getWritableDatabase(); mAccountsDbAdapter = new AccountsDbAdapter(db); Cursor cursor = mAccountsDbAdapter.fetchAllRecordsOrderedByFullName(); mAccountsCursorAdapter.swapCursor(cursor); mAccountsCursorAdapter.notifyDataSetChanged(); } @Override public void onNothingSelected(AdapterView<?> parent) { //nothing to see here, move along } }); mOkButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { 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; } String bookUID = BooksDbAdapter.getInstance().getUID(mBooksSpinner.getSelectedItemId()); String accountUID = mAccountsDbAdapter.getUID(mAccountsSpinner.getSelectedItemId()); boolean hideAccountBalance = mHideAccountBalance.isChecked(); configureWidget(WidgetConfigurationActivity.this, mAppWidgetId, bookUID, accountUID, hideAccountBalance); updateWidget(WidgetConfigurationActivity.this, mAppWidgetId); Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); finish(); } }); mCancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); }
From source file:com.teinproductions.tein.papyrosprogress.MainActivity.java
private void restoreAppWidgetStuff() { if (Build.VERSION.SDK_INT < 16) return;/*from w w w.jav a 2 s. c o m*/ Bundle extras = getIntent().getExtras(); if (extras != null) { appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); adapter.setTextSize(pref.getInt(Constants.TEXT_SIZE_PREFERENCE + appWidgetId, 24)); adapter.setWidgetMilestoneTitle( pref.getString(Constants.MILESTONE_WIDGET_PREFERENCE + appWidgetId, null)); } else { adapter.setTextSize(PapyrosRecyclerAdapter.DONT_SHOW_TEXT_SIZE_TILE); } }
From source file:eu.power_switch.widget.activity.ConfigureReceiverWidgetActivity.java
private void saveCurrentConfiguration() { try {//from w w w.jav a 2s . c o m // First, get the App Widget ID from the Intent that launched the Activity: Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null && extras.containsKey(AppWidgetManager.EXTRA_APPWIDGET_ID)) { int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); // Perform your App Widget configuration: Apartment selectedApartment = getSelectedApartment(); Room selectedRoom = selectedApartment.getRoom(spinnerRoom.getSelectedItem().toString()); Receiver selectedReceiver = selectedRoom.getReceiver(spinnerReceiver.getSelectedItem().toString()); // save new widget data to database ReceiverWidget receiverWidget = new ReceiverWidget(appWidgetId, selectedRoom.getId(), selectedReceiver.getId()); DatabaseHandler.addReceiverWidget(receiverWidget); // When the configuration is complete, get an instance of // the AppWidgetManager by calling getInstance(Context): AppWidgetManager appWidgetManager = AppWidgetManager .getInstance(ConfigureReceiverWidgetActivity.this); // Update the App Widget with a RemoteViews layout by // calling updateAppWidget(int, RemoteViews): RemoteViews remoteViews = new RemoteViews(getString(eu.power_switch.shared.R.string.PACKAGE_NAME), R.layout.widget_receiver); LinkedList<Button> buttons = selectedReceiver.getButtons(); remoteViews.setTextViewText(R.id.textView_receiver_widget_name, selectedApartment.getName() + ": " + selectedRoom.getName() + ": " + selectedReceiver.getName()); int buttonOffset = 0; for (Button button : buttons) { // set button action RemoteViews buttonView = new RemoteViews( getString(eu.power_switch.shared.R.string.PACKAGE_NAME), R.layout.widget_receiver_button_layout); SpannableString s = new SpannableString(button.getName()); s.setSpan(new StyleSpan(Typeface.BOLD), 0, button.getName().length(), 0); buttonView.setTextViewText(R.id.button_widget_universal, s); if (SmartphonePreferencesHandler.getHighlightLastActivatedButton() && selectedReceiver.getLastActivatedButtonId().equals(button.getId())) { buttonView.setTextColor(R.id.button_widget_universal, ContextCompat.getColor(getApplicationContext(), R.color.color_light_blue_a700)); } PendingIntent pendingIntent = WidgetIntentReceiver.buildReceiverWidgetActionPendingIntent( getApplicationContext(), selectedApartment, selectedRoom, selectedReceiver, button, appWidgetId * 15 + buttonOffset); buttonView.setOnClickPendingIntent(R.id.button_widget_universal, pendingIntent); remoteViews.addView(R.id.linearlayout_receiver_widget, buttonView); buttonOffset++; } appWidgetManager.updateAppWidget(appWidgetId, remoteViews); // Finally, create the return Intent, set it with the // Activity result, and finish the Activity: Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); setResult(RESULT_OK, resultValue); finish(); } } catch (Exception e) { StatusMessageHandler.showErrorMessage(this, e); } }
From source file:com.songcode.materialnotes.ui.NotesListActivity.java
private void setAppInfoFromRawRes() { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) { StringBuilder sb = new StringBuilder(); InputStream in = null;// w ww. j a va 2 s . c o m try { in = getResources().openRawResource(R.raw.introduction); if (in != null) { InputStreamReader isr = new InputStreamReader(in); BufferedReader br = new BufferedReader(isr); char[] buf = new char[1024]; int len = 0; while ((len = br.read(buf)) > 0) { sb.append(buf, 0, len); } } else { Log.e(TAG, "Read introduction file error"); return; } } catch (IOException e) { e.printStackTrace(); return; } finally { if (in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER, AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE, ResourceParser.RED); note.setWorkingText(sb.toString()); if (note.saveNote()) { sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit(); } else { Log.e(TAG, "Save introduction note error"); return; } } }
From source file:ch.fixme.status.Main.java
private void showHsInfo(Intent intent, Bundle savedInstanceState) { // Get hackerspace api url if (intent != null && intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { mApiUrl = mPrefs.getString(PREF_API_URL_WIDGET + intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID), ParseGeneric.API_DEFAULT); } else if (intent != null && intent.hasExtra(STATE_HS)) { mApiUrl = intent.getStringExtra(STATE_HS); } else {//from w w w . j av a 2 s .c om mApiUrl = mPrefs.getString(PREF_API_URL, ParseGeneric.API_DEFAULT); } // Get Data final Bundle data = (Bundle) getLastNonConfigurationInstance(); if (data == null || (savedInstanceState == null && !savedInstanceState.containsKey(STATE_HS))) { getApiTask = new GetApiTask(); getApiTask.execute(mApiUrl); } else { finishApi = true; mResultHs = data.getString(STATE_HS); populateDataHs(); } // Update widget Widget.UpdateAllWidgets(getApplicationContext()); }
From source file:com.forrestguice.suntimeswidget.notes.SuntimesNotes1.java
@Override public void updateNote(Context context, Calendar now, int transition) { SolarEvents noteMode;/*from w w w . j a v a2 s .com*/ int noteIcon, noteColor; SuntimesUtils.TimeDisplayText timeString; String noteString, untilString; Date timestamp; Date time = now.getTime(); Date sunrise = dataset.dataActual.sunriseCalendarToday().getTime(); Date sunsetAstroTwilight = dataset.dataAstro.sunsetCalendarToday().getTime(); boolean afterSunriseToday = time.after(sunrise); if (afterSunriseToday && time.before(sunsetAstroTwilight)) { // a time after sunrise (but before night) noteIcon = R.drawable.ic_sunset_large; noteColor = ContextCompat.getColor(context, R.color.sunIcon_color_setting); int setChoice = WidgetSettings.loadTimeNoteSetPref(context, AppWidgetManager.INVALID_APPWIDGET_ID) .ordinal(); Date sunset = dataset.dataActual.sunsetCalendarToday().getTime(); if (time.before(sunset) && setChoice <= 1) { untilString = context.getString(R.string.until); Date noon = dataset.dataNoon.sunriseCalendarToday().getTime(); if (time.before(noon) && setChoice <= 0) { // morning: note the time until noon noteIcon = R.drawable.ic_noon_large; timestamp = noon; noteMode = SolarEvents.NOON; timeString = utils.timeDeltaDisplayString(time, noon); noteString = context.getString(R.string.until_noon); } else { // afternoon: note the time until sunset timestamp = sunset; noteMode = SolarEvents.SUNSET; timeString = utils.timeDeltaDisplayString(time, sunset); noteString = context.getString(R.string.until_sunset); } } else { untilString = context.getString(R.string.until_end); Date civilTwilight = dataset.dataCivil.sunsetCalendarToday().getTime(); if (time.before(civilTwilight) && setChoice <= 2) { // civil twilight: note time until end of civil twilight timestamp = civilTwilight; noteMode = SolarEvents.EVENING_CIVIL; timeString = utils.timeDeltaDisplayString(time, civilTwilight); noteString = context.getString(R.string.untilEnd_civilTwilight); } else { Date nauticalTwilight = dataset.dataNautical.sunsetCalendarToday().getTime(); if (time.before(nauticalTwilight) && setChoice <= 3) { // nautical twilight: note time until end of nautical twilight timestamp = nauticalTwilight; noteMode = SolarEvents.EVENING_NAUTICAL; timeString = utils.timeDeltaDisplayString(time, nauticalTwilight); noteString = context.getString(R.string.untilEnd_nauticalTwilight); } else { // astronomical twilight: note time until night timestamp = sunsetAstroTwilight; noteMode = SolarEvents.EVENING_ASTRONOMICAL; timeString = utils.timeDeltaDisplayString(time, sunsetAstroTwilight); noteString = context.getString(R.string.untilEnd_astroTwilight); } } } } else { // a time before sunrise noteIcon = R.drawable.ic_sunrise_large; untilString = context.getString(R.string.until); noteColor = ContextCompat.getColor(context, R.color.sunIcon_color_rising); int riseChoice = WidgetSettings.loadTimeNoteRisePref(context, AppWidgetManager.INVALID_APPWIDGET_ID) .ordinal(); Date astroTwilight = afterSunriseToday ? dataset.dataAstro.sunriseCalendarOther().getTime() : dataset.dataAstro.sunriseCalendarToday().getTime(); if (time.before(astroTwilight) && riseChoice <= 0) { // night: note time until astro twilight today timestamp = astroTwilight; noteMode = SolarEvents.MORNING_ASTRONOMICAL; timeString = utils.timeDeltaDisplayString(time, astroTwilight); noteString = context.getString(R.string.until_astroTwilight); } else { Date nauticalTwilight = afterSunriseToday ? dataset.dataNautical.sunriseCalendarOther().getTime() : dataset.dataNautical.sunriseCalendarToday().getTime(); if (time.before(nauticalTwilight) && riseChoice <= 1) { // astronomical twilight: note time until nautical twilight timestamp = nauticalTwilight; noteMode = SolarEvents.MORNING_NAUTICAL; timeString = utils.timeDeltaDisplayString(time, nauticalTwilight); noteString = context.getString(R.string.until_nauticalTwilight); } else { Date civilTwilight = afterSunriseToday ? dataset.dataCivil.sunriseCalendarOther().getTime() : dataset.dataCivil.sunriseCalendarToday().getTime(); if (time.before(civilTwilight) && riseChoice <= 2) { // nautical twilight: note time until civil twilight timestamp = civilTwilight; noteMode = SolarEvents.MORNING_CIVIL; timeString = utils.timeDeltaDisplayString(time, civilTwilight); noteString = context.getString(R.string.until_civilTwilight); } else { if (riseChoice <= 3) { // civil twilight: note time until sunrise sunrise = afterSunriseToday ? dataset.dataActual.sunriseCalendarOther().getTime() : dataset.dataActual.sunriseCalendarToday().getTime(); timestamp = sunrise; noteMode = SolarEvents.SUNRISE; timeString = utils.timeDeltaDisplayString(time, sunrise); noteString = context.getString(R.string.until_sunrise); } else { // civil twilight: note time until noon Date noon = dataset.dataNoon.sunriseCalendarToday().getTime(); boolean afterNoonToday = time.after(noon); if (afterNoonToday) { noon = dataset.dataNoon.sunriseCalendarOther().getTime(); } timestamp = noon; noteMode = SolarEvents.NOON; noteIcon = R.drawable.ic_noon_large; timeString = utils.timeDeltaDisplayString(time, noon); noteString = context.getString(R.string.until_noon); } } } } } NoteData note = new NoteData(noteMode, timeString, untilString, noteString, noteIcon, noteColor); note.time = timestamp; if (currentNote == null) { setNote(note, NoteChangedListener.TRANSITION_NEXT); } else if (!currentNote.equals(note)) { setNote(note, NoteChangedListener.TRANSITION_NEXT); } }
From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.subredditselect); // load personal list from saved prefereces, if null use default and save mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(SubredditSelectActivity.this); global = ((GlobalObjects) SubredditSelectActivity.this.getApplicationContext()); // get subreddit list and set adapter subredditList = global.getSubredditManager().getSubredditNames(); subsAdapter = new MySubredditsAdapter(this, subredditList); ListView subListView = (ListView) findViewById(R.id.sublist); subListView.setAdapter(subsAdapter); subListView.setTextFilterEnabled(true); subListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String subreddit = ((TextView) view.findViewById(R.id.subreddit_name)).getText().toString(); global.getSubredditManager().setFeedSubreddit(mAppWidgetId, subreddit); updateFeedAndFinish();/*from w ww .j av a 2s .c o m*/ //System.out.println(sreddit+" selected"); } }); subsAdapter.sort(new Comparator<String>() { @Override public int compare(String s, String t1) { return s.compareToIgnoreCase(t1); } }); // get multi list and set adapter mMultiAdapter = new MyMultisAdapter(this); ListView multiListView = (ListView) findViewById(R.id.multilist); multiListView.setAdapter(mMultiAdapter); multiListView.setTextFilterEnabled(true); multiListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == mMultiAdapter.getCount() - 1) { LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.dialog_multi_add, parent, false); final EditText name = (EditText) layout.findViewById(R.id.new_multi_name); AlertDialog.Builder builder = new AlertDialog.Builder(SubredditSelectActivity.this); builder.setTitle("Create A Multi").setView(layout) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (name.getText().toString().equals("")) { Toast.makeText(SubredditSelectActivity.this, "Please enter a name for the multi", Toast.LENGTH_LONG).show(); return; } new SubscriptionEditTask(SubscriptionEditTask.ACTION_MULTI_CREATE) .execute(name.getText().toString()); dialogInterface.dismiss(); } }).show(); } else { JSONObject multiObj = mMultiAdapter.getItem(position); try { String name = multiObj.getString("display_name"); String path = multiObj.getString("path"); global.getSubredditManager().setFeed(mAppWidgetId, name, path, true); updateFeedAndFinish(); } catch (JSONException e) { e.printStackTrace(); Toast.makeText(SubredditSelectActivity.this, "Error setting multi.", Toast.LENGTH_LONG) .show(); } } } }); 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) { mAppWidgetId = 0; // Id of 4 zeros indicates its the app view, not a widget, that is being updated } else { String action = getIntent().getAction(); widgetFirstTimeSetup = action != null && action.equals("android.appwidget.action.APPWIDGET_CONFIGURE"); } } else { mAppWidgetId = 0; } final ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new SimpleTabsAdapter(new String[] { "My Subreddits", "My Multis" }, new int[] { R.id.sublist, R.id.multilist }, SubredditSelectActivity.this, null)); LinearLayout tabsLayout = (LinearLayout) findViewById(R.id.tab_widget); tabs = new SimpleTabsWidget(SubredditSelectActivity.this, tabsLayout); tabs.setViewPager(pager); addButton = (Button) findViewById(R.id.addsrbutton); addButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(SubredditSelectActivity.this, ViewAllSubredditsActivity.class); startActivityForResult(intent, 1); } }); refreshButton = (Button) findViewById(R.id.refreshloginbutton); refreshButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (global.mRedditData.isLoggedIn()) { if (pager.getCurrentItem() == 1) { refreshMultireddits(); } else { refreshSubreddits(); } } else { global.mRedditData.initiateLogin(SubredditSelectActivity.this); } } }); // sort button sortBtn = (Button) findViewById(R.id.sortselect); String sortTxt = "Sort: " + mSharedPreferences.getString("sort-" + (mAppWidgetId == 0 ? "app" : mAppWidgetId), "hot"); sortBtn.setText(sortTxt); sortBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { showSortDialog(); } }); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } // set theme colors setThemeColors(); GlobalObjects.doShowWelcomeDialog(SubredditSelectActivity.this); }