List of usage examples for android.content Intent getIntExtra
public int getIntExtra(String name, int defaultValue)
From source file:com.piusvelte.sonet.core.SonetService.java
private void start(Intent intent) { if (intent != null) { String action = intent.getAction(); Log.d(TAG, "action:" + action); if (ACTION_REFRESH.equals(action)) { if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)) putValidatedUpdates(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), 1); else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) putValidatedUpdates(new int[] { intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) }, 1); else if (intent.getData() != null) putValidatedUpdates(new int[] { Integer.parseInt(intent.getData().getLastPathSegment()) }, 1); else//from w w w .jav a 2 s . com putValidatedUpdates(null, 0); } else if (LauncherIntent.Action.ACTION_READY.equals(action)) { if (intent.hasExtra(EXTRA_SCROLLABLE_VERSION) && intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { int scrollableVersion = intent.getIntExtra(EXTRA_SCROLLABLE_VERSION, 1); int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); // check if the scrollable needs to be built Cursor widget = this.getContentResolver().query(Widgets.getContentUri(SonetService.this), new String[] { Widgets._ID, Widgets.SCROLLABLE }, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }, null); if (widget.moveToFirst()) { if (widget.getInt(widget.getColumnIndex(Widgets.SCROLLABLE)) < scrollableVersion) { ContentValues values = new ContentValues(); values.put(Widgets.SCROLLABLE, scrollableVersion); // set the scrollable version this.getContentResolver().update(Widgets.getContentUri(SonetService.this), values, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); putValidatedUpdates(new int[] { appWidgetId }, 1); } else putValidatedUpdates(new int[] { appWidgetId }, 1); } else { ContentValues values = new ContentValues(); values.put(Widgets.SCROLLABLE, scrollableVersion); // set the scrollable version this.getContentResolver().update(Widgets.getContentUri(SonetService.this), values, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); putValidatedUpdates(new int[] { appWidgetId }, 1); } widget.close(); } else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { // requery putValidatedUpdates(new int[] { intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) }, 0); } } else if (SMS_RECEIVED.equals(action)) { // parse the sms, and notify any widgets which have sms enabled Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdus.length; i++) { SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]); AsyncTask<SmsMessage, String, int[]> smsLoader = new AsyncTask<SmsMessage, String, int[]>() { @Override protected int[] doInBackground(SmsMessage... msg) { // check if SMS is enabled anywhere Cursor widgets = getContentResolver().query( Widget_accounts_view.getContentUri(SonetService.this), new String[] { Widget_accounts_view._ID, Widget_accounts_view.WIDGET, Widget_accounts_view.ACCOUNT }, Widget_accounts_view.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); int[] appWidgetIds = new int[widgets.getCount()]; if (widgets.moveToFirst()) { // insert this message to the statuses db and requery scrollable/rebuild widget // check if this is a contact String phone = msg[0].getOriginatingAddress(); String friend = phone; byte[] profile = null; Uri content_uri = null; // unknown numbers crash here in the emulator Cursor phones = getContentResolver().query( Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone)), new String[] { ContactsContract.PhoneLookup._ID }, null, null, null); if (phones.moveToFirst()) content_uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, phones.getLong(0)); else { Cursor emails = getContentResolver().query( Uri.withAppendedPath( ContactsContract.CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(phone)), new String[] { ContactsContract.CommonDataKinds.Email._ID }, null, null, null); if (emails.moveToFirst()) content_uri = ContentUris.withAppendedId( ContactsContract.Contacts.CONTENT_URI, emails.getLong(0)); emails.close(); } phones.close(); if (content_uri != null) { // load contact Cursor contacts = getContentResolver().query(content_uri, new String[] { ContactsContract.Contacts.DISPLAY_NAME }, null, null, null); if (contacts.moveToFirst()) friend = contacts.getString(0); contacts.close(); profile = getBlob(ContactsContract.Contacts .openContactPhotoInputStream(getContentResolver(), content_uri)); } long accountId = widgets.getLong(2); long id; ContentValues values = new ContentValues(); values.put(Entities.ESID, phone); values.put(Entities.FRIEND, friend); values.put(Entities.PROFILE, profile); values.put(Entities.ACCOUNT, accountId); Cursor entity = getContentResolver().query( Entities.getContentUri(SonetService.this), new String[] { Entities._ID }, Entities.ACCOUNT + "=? and " + Entities.ESID + "=?", new String[] { Long.toString(accountId), mSonetCrypto.Encrypt(phone) }, null); if (entity.moveToFirst()) { id = entity.getLong(0); getContentResolver().update(Entities.getContentUri(SonetService.this), values, Entities._ID + "=?", new String[] { Long.toString(id) }); } else id = Long.parseLong(getContentResolver() .insert(Entities.getContentUri(SonetService.this), values) .getLastPathSegment()); entity.close(); values.clear(); Long created = msg[0].getTimestampMillis(); values.put(Statuses.CREATED, created); values.put(Statuses.ENTITY, id); values.put(Statuses.MESSAGE, msg[0].getMessageBody()); values.put(Statuses.SERVICE, SMS); while (!widgets.isAfterLast()) { int widget = widgets.getInt(1); appWidgetIds[widgets.getPosition()] = widget; // get settings boolean time24hr = true; int status_bg_color = Sonet.default_message_bg_color; int profile_bg_color = Sonet.default_message_bg_color; int friend_bg_color = Sonet.default_friend_bg_color; boolean icon = true; int status_count = Sonet.default_statuses_per_account; int notifications = 0; Cursor c = getContentResolver().query( Widgets_settings.getContentUri(SonetService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(accountId) }, null); if (!c.moveToFirst()) { c.close(); c = getContentResolver().query( Widgets_settings.getContentUri(SonetService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(Sonet.INVALID_ACCOUNT_ID) }, null); if (!c.moveToFirst()) { c.close(); c = getContentResolver().query( Widgets_settings.getContentUri(SonetService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(AppWidgetManager.INVALID_APPWIDGET_ID), Long.toString(Sonet.INVALID_ACCOUNT_ID) }, null); if (!c.moveToFirst()) initAccountSettings(SonetService.this, AppWidgetManager.INVALID_APPWIDGET_ID, Sonet.INVALID_ACCOUNT_ID); if (widget != AppWidgetManager.INVALID_APPWIDGET_ID) initAccountSettings(SonetService.this, widget, Sonet.INVALID_ACCOUNT_ID); } initAccountSettings(SonetService.this, widget, accountId); } if (c.moveToFirst()) { time24hr = c.getInt(0) == 1; status_bg_color = c.getInt(1); icon = c.getInt(2) == 1; status_count = c.getInt(3); if (c.getInt(4) == 1) notifications |= Notification.DEFAULT_SOUND; if (c.getInt(5) == 1) notifications |= Notification.DEFAULT_VIBRATE; if (c.getInt(6) == 1) notifications |= Notification.DEFAULT_LIGHTS; profile_bg_color = c.getInt(7); friend_bg_color = c.getInt(8); } c.close(); values.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(created, time24hr)); // update the bg and icon // create the status_bg values.put(Statuses.STATUS_BG, createBackground(status_bg_color)); // friend_bg values.put(Statuses.FRIEND_BG, createBackground(friend_bg_color)); // profile_bg values.put(Statuses.PROFILE_BG, createBackground(profile_bg_color)); values.put(Statuses.ICON, icon ? getBlob(getResources(), map_icons[SMS]) : null); // insert the message values.put(Statuses.WIDGET, widget); values.put(Statuses.ACCOUNT, accountId); getContentResolver().insert(Statuses.getContentUri(SonetService.this), values); // check the status count, removing old sms Cursor statuses = getContentResolver().query( Statuses.getContentUri(SonetService.this), new String[] { Statuses._ID }, Statuses.WIDGET + "=? and " + Statuses.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(accountId) }, Statuses.CREATED + " desc"); if (statuses.moveToFirst()) { while (!statuses.isAfterLast()) { if (statuses.getPosition() >= status_count) { getContentResolver().delete( Statuses.getContentUri(SonetService.this), Statuses._ID + "=?", new String[] { Long.toString(statuses .getLong(statuses.getColumnIndex(Statuses._ID))) }); } statuses.moveToNext(); } } statuses.close(); if (notifications != 0) publishProgress(Integer.toString(notifications), friend + " sent a message"); widgets.moveToNext(); } } widgets.close(); return appWidgetIds; } @Override protected void onProgressUpdate(String... updates) { int notifications = Integer.parseInt(updates[0]); if (notifications != 0) { Notification notification = new Notification(R.drawable.notification, updates[1], System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "New messages", updates[1], PendingIntent.getActivity(SonetService.this, 0, (Sonet .getPackageIntent(SonetService.this, SonetNotifications.class)), 0)); notification.defaults |= notifications; ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .notify(NOTIFY_ID, notification); } } @Override protected void onPostExecute(int[] appWidgetIds) { // remove self from thread list if (!mSMSLoaders.isEmpty()) mSMSLoaders.remove(this); putValidatedUpdates(appWidgetIds, 0); } }; mSMSLoaders.add(smsLoader); smsLoader.execute(msg); } } else if (ACTION_PAGE_DOWN.equals(action)) (new PagingTask()).execute(Integer.parseInt(intent.getData().getLastPathSegment()), intent.getIntExtra(ACTION_PAGE_DOWN, 0)); else if (ACTION_PAGE_UP.equals(action)) (new PagingTask()).execute(Integer.parseInt(intent.getData().getLastPathSegment()), intent.getIntExtra(ACTION_PAGE_UP, 0)); else { // this might be a widget update from the widget refresh button int appWidgetId; try { appWidgetId = Integer.parseInt(action); putValidatedUpdates(new int[] { appWidgetId }, 1); } catch (NumberFormatException e) { Log.d(TAG, "unknown action:" + action); } } } }
From source file:com.shafiq.myfeedle.core.MyfeedleService.java
private void start(Intent intent) { if (intent != null) { String action = intent.getAction(); Log.d(TAG, "action:" + action); if (ACTION_REFRESH.equals(action)) { if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)) putValidatedUpdates(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), 1); else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) putValidatedUpdates(new int[] { intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) }, 1); else if (intent.getData() != null) putValidatedUpdates(new int[] { Integer.parseInt(intent.getData().getLastPathSegment()) }, 1); else//w ww .j av a 2s . c o m putValidatedUpdates(null, 0); } else if (LauncherIntent.Action.ACTION_READY.equals(action)) { if (intent.hasExtra(EXTRA_SCROLLABLE_VERSION) && intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { int scrollableVersion = intent.getIntExtra(EXTRA_SCROLLABLE_VERSION, 1); int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); // check if the scrollable needs to be built Cursor widget = this.getContentResolver().query(Widgets.getContentUri(MyfeedleService.this), new String[] { Widgets._ID, Widgets.SCROLLABLE }, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }, null); if (widget.moveToFirst()) { if (widget.getInt(widget.getColumnIndex(Widgets.SCROLLABLE)) < scrollableVersion) { ContentValues values = new ContentValues(); values.put(Widgets.SCROLLABLE, scrollableVersion); // set the scrollable version this.getContentResolver().update(Widgets.getContentUri(MyfeedleService.this), values, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); putValidatedUpdates(new int[] { appWidgetId }, 1); } else putValidatedUpdates(new int[] { appWidgetId }, 1); } else { ContentValues values = new ContentValues(); values.put(Widgets.SCROLLABLE, scrollableVersion); // set the scrollable version this.getContentResolver().update(Widgets.getContentUri(MyfeedleService.this), values, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); putValidatedUpdates(new int[] { appWidgetId }, 1); } widget.close(); } else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { // requery putValidatedUpdates(new int[] { intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) }, 0); } } else if (SMS_RECEIVED.equals(action)) { // parse the sms, and notify any widgets which have sms enabled Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdus.length; i++) { SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]); AsyncTask<SmsMessage, String, int[]> smsLoader = new AsyncTask<SmsMessage, String, int[]>() { @Override protected int[] doInBackground(SmsMessage... msg) { // check if SMS is enabled anywhere Cursor widgets = getContentResolver().query( Widget_accounts_view.getContentUri(MyfeedleService.this), new String[] { Widget_accounts_view._ID, Widget_accounts_view.WIDGET, Widget_accounts_view.ACCOUNT }, Widget_accounts_view.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); int[] appWidgetIds = new int[widgets.getCount()]; if (widgets.moveToFirst()) { // insert this message to the statuses db and requery scrollable/rebuild widget // check if this is a contact String phone = msg[0].getOriginatingAddress(); String friend = phone; byte[] profile = null; Uri content_uri = null; // unknown numbers crash here in the emulator Cursor phones = getContentResolver().query( Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone)), new String[] { ContactsContract.PhoneLookup._ID }, null, null, null); if (phones.moveToFirst()) content_uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, phones.getLong(0)); else { Cursor emails = getContentResolver().query( Uri.withAppendedPath( ContactsContract.CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(phone)), new String[] { ContactsContract.CommonDataKinds.Email._ID }, null, null, null); if (emails.moveToFirst()) content_uri = ContentUris.withAppendedId( ContactsContract.Contacts.CONTENT_URI, emails.getLong(0)); emails.close(); } phones.close(); if (content_uri != null) { // load contact Cursor contacts = getContentResolver().query(content_uri, new String[] { ContactsContract.Contacts.DISPLAY_NAME }, null, null, null); if (contacts.moveToFirst()) friend = contacts.getString(0); contacts.close(); profile = getBlob(ContactsContract.Contacts .openContactPhotoInputStream(getContentResolver(), content_uri)); } long accountId = widgets.getLong(2); long id; ContentValues values = new ContentValues(); values.put(Entities.ESID, phone); values.put(Entities.FRIEND, friend); values.put(Entities.PROFILE, profile); values.put(Entities.ACCOUNT, accountId); Cursor entity = getContentResolver().query( Entities.getContentUri(MyfeedleService.this), new String[] { Entities._ID }, Entities.ACCOUNT + "=? and " + Entities.ESID + "=?", new String[] { Long.toString(accountId), mMyfeedleCrypto.Encrypt(phone) }, null); if (entity.moveToFirst()) { id = entity.getLong(0); getContentResolver().update(Entities.getContentUri(MyfeedleService.this), values, Entities._ID + "=?", new String[] { Long.toString(id) }); } else id = Long.parseLong(getContentResolver() .insert(Entities.getContentUri(MyfeedleService.this), values) .getLastPathSegment()); entity.close(); values.clear(); Long created = msg[0].getTimestampMillis(); values.put(Statuses.CREATED, created); values.put(Statuses.ENTITY, id); values.put(Statuses.MESSAGE, msg[0].getMessageBody()); values.put(Statuses.SERVICE, SMS); while (!widgets.isAfterLast()) { int widget = widgets.getInt(1); appWidgetIds[widgets.getPosition()] = widget; // get settings boolean time24hr = true; int status_bg_color = Myfeedle.default_message_bg_color; int profile_bg_color = Myfeedle.default_message_bg_color; int friend_bg_color = Myfeedle.default_friend_bg_color; boolean icon = true; int status_count = Myfeedle.default_statuses_per_account; int notifications = 0; Cursor c = getContentResolver().query( Widgets_settings.getContentUri(MyfeedleService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(accountId) }, null); if (!c.moveToFirst()) { c.close(); c = getContentResolver().query( Widgets_settings.getContentUri(MyfeedleService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(Myfeedle.INVALID_ACCOUNT_ID) }, null); if (!c.moveToFirst()) { c.close(); c = getContentResolver().query( Widgets_settings.getContentUri(MyfeedleService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(AppWidgetManager.INVALID_APPWIDGET_ID), Long.toString(Myfeedle.INVALID_ACCOUNT_ID) }, null); if (!c.moveToFirst()) initAccountSettings(MyfeedleService.this, AppWidgetManager.INVALID_APPWIDGET_ID, Myfeedle.INVALID_ACCOUNT_ID); if (widget != AppWidgetManager.INVALID_APPWIDGET_ID) initAccountSettings(MyfeedleService.this, widget, Myfeedle.INVALID_ACCOUNT_ID); } initAccountSettings(MyfeedleService.this, widget, accountId); } if (c.moveToFirst()) { time24hr = c.getInt(0) == 1; status_bg_color = c.getInt(1); icon = c.getInt(2) == 1; status_count = c.getInt(3); if (c.getInt(4) == 1) notifications |= Notification.DEFAULT_SOUND; if (c.getInt(5) == 1) notifications |= Notification.DEFAULT_VIBRATE; if (c.getInt(6) == 1) notifications |= Notification.DEFAULT_LIGHTS; profile_bg_color = c.getInt(7); friend_bg_color = c.getInt(8); } c.close(); values.put(Statuses.CREATEDTEXT, Myfeedle.getCreatedText(created, time24hr)); // update the bg and icon // create the status_bg values.put(Statuses.STATUS_BG, createBackground(status_bg_color)); // friend_bg values.put(Statuses.FRIEND_BG, createBackground(friend_bg_color)); // profile_bg values.put(Statuses.PROFILE_BG, createBackground(profile_bg_color)); values.put(Statuses.ICON, icon ? getBlob(getResources(), map_icons[SMS]) : null); // insert the message values.put(Statuses.WIDGET, widget); values.put(Statuses.ACCOUNT, accountId); getContentResolver().insert(Statuses.getContentUri(MyfeedleService.this), values); // check the status count, removing old sms Cursor statuses = getContentResolver().query( Statuses.getContentUri(MyfeedleService.this), new String[] { Statuses._ID }, Statuses.WIDGET + "=? and " + Statuses.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(accountId) }, Statuses.CREATED + " desc"); if (statuses.moveToFirst()) { while (!statuses.isAfterLast()) { if (statuses.getPosition() >= status_count) { getContentResolver().delete( Statuses.getContentUri(MyfeedleService.this), Statuses._ID + "=?", new String[] { Long.toString(statuses .getLong(statuses.getColumnIndex(Statuses._ID))) }); } statuses.moveToNext(); } } statuses.close(); if (notifications != 0) publishProgress(Integer.toString(notifications), friend + " sent a message"); widgets.moveToNext(); } } widgets.close(); return appWidgetIds; } @Override protected void onProgressUpdate(String... updates) { int notifications = Integer.parseInt(updates[0]); if (notifications != 0) { Notification notification = new Notification(R.drawable.notification, updates[1], System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "New messages", updates[1], PendingIntent.getActivity(MyfeedleService.this, 0, (Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleNotifications.class)), 0)); notification.defaults |= notifications; ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .notify(NOTIFY_ID, notification); } } @Override protected void onPostExecute(int[] appWidgetIds) { // remove self from thread list if (!mSMSLoaders.isEmpty()) mSMSLoaders.remove(this); putValidatedUpdates(appWidgetIds, 0); } }; mSMSLoaders.add(smsLoader); smsLoader.execute(msg); } } else if (ACTION_PAGE_DOWN.equals(action)) (new PagingTask()).execute(Integer.parseInt(intent.getData().getLastPathSegment()), intent.getIntExtra(ACTION_PAGE_DOWN, 0)); else if (ACTION_PAGE_UP.equals(action)) (new PagingTask()).execute(Integer.parseInt(intent.getData().getLastPathSegment()), intent.getIntExtra(ACTION_PAGE_UP, 0)); else { // this might be a widget update from the widget refresh button int appWidgetId; try { appWidgetId = Integer.parseInt(action); putValidatedUpdates(new int[] { appWidgetId }, 1); } catch (NumberFormatException e) { Log.d(TAG, "unknown action:" + action); } } } }
From source file:com.andrew.apolloMod.service.ApolloService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { mServiceStartId = startId;// w ww .j a v a2 s . c o m mDelayedStopHandler.removeCallbacksAndMessages(null); if (intent != null) { String action = intent.getAction(); String cmd = intent.getStringExtra("command"); if (CMDNEXT.equals(cmd) || NEXT_ACTION.equals(action)) { gotoNext(true); } else if (CMDPREVIOUS.equals(cmd) || PREVIOUS_ACTION.equals(action)) { if (position() < 2000) { prev(); } else { seek(0); play(); } } else if (CMDTOGGLEPAUSE.equals(cmd) || TOGGLEPAUSE_ACTION.equals(action)) { if (mIsSupposedToBePlaying) { pause(); mPausedByTransientLossOfFocus = false; } else { play(); } } else if (CMDPAUSE.equals(cmd) || PAUSE_ACTION.equals(action)) { pause(); mPausedByTransientLossOfFocus = false; } else if (CMDPLAY.equals(cmd)) { play(); } else if (CMDSTOP.equals(cmd)) { pause(); if (intent.getIntExtra(CMDNOTIF, 0) == 3) { stopForeground(true); } mPausedByTransientLossOfFocus = false; seek(0); } else if (CMDTOGGLEFAVORITE.equals(cmd)) { if (!isFavorite()) { addToFavorites(); } else { removeFromFavorites(); } } else if (CMDCYCLEREPEAT.equals(cmd) || CYCLEREPEAT_ACTION.equals(action)) { cycleRepeat(); } else if (CMDTOGGLESHUFFLE.equals(cmd) || TOGGLESHUFFLE_ACTION.equals(action)) { toggleShuffle(); } } // make sure the service will shut down on its own if it was // just started but not bound to and nothing is playing mDelayedStopHandler.removeCallbacksAndMessages(null); Message msg = mDelayedStopHandler.obtainMessage(); mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY); return START_STICKY; }
From source file:com.android.tv.MainActivity.java
private boolean handleIntent(Intent intent) { // Reset the closed caption settings when the activity is 1)created or 2) restarted. // And do not reset while TvView is playing. if (!mTvView.isPlaying()) { mCaptionSettings = new CaptionSettings(this); }//from w w w. java2 s. c o m // Handle the passed key press, if any. Note that only the key codes that are currently // handled in the TV app will be handled via Intent. // TODO: Consider defining a separate intent filter as passing data of mime type // vnd.android.cursor.item/channel isn't really necessary here. int keyCode = intent.getIntExtra(Utils.EXTRA_KEY_KEYCODE, KeyEvent.KEYCODE_UNKNOWN); if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { if (DEBUG) Log.d(TAG, "Got an intent with keycode: " + keyCode); KeyEvent event = new KeyEvent(KeyEvent.ACTION_UP, keyCode); onKeyUp(keyCode, event); return true; } mShouldTuneToTunerChannel = intent.getBooleanExtra(Utils.EXTRA_KEY_FROM_LAUNCHER, false); mInitChannelUri = null; String extraAction = intent.getStringExtra(Utils.EXTRA_KEY_ACTION); if (!TextUtils.isEmpty(extraAction)) { if (DEBUG) Log.d(TAG, "Got an extra action: " + extraAction); if (Utils.EXTRA_ACTION_SHOW_TV_INPUT.equals(extraAction)) { String lastWatchedChannelUri = Utils.getLastWatchedChannelUri(this); if (lastWatchedChannelUri != null) { mInitChannelUri = Uri.parse(lastWatchedChannelUri); } mShowSelectInputView = true; } } if (CommonFeatures.DVR.isEnabled(this) && BuildCompat.isAtLeastN()) { mRecordingUri = intent.getParcelableExtra(Utils.EXTRA_KEY_RECORDING_URI); if (mRecordingUri != null) { return true; } } // TODO: remove the checkState once N API is finalized. SoftPreconditions .checkState(TvInputManager.ACTION_SETUP_INPUTS.equals("android.media.tv.action.SETUP_INPUTS")); if (TvInputManager.ACTION_SETUP_INPUTS.equals(intent.getAction())) { runAfterAttachedToWindow(new Runnable() { @Override public void run() { mOverlayManager.showSetupFragment(); } }); } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { Uri uri = intent.getData(); try { mSource = uri.getQueryParameter(Utils.PARAM_SOURCE); } catch (UnsupportedOperationException e) { // ignore this exception. } // When the URI points to the programs (directory, not an individual item), go to the // program guide. The intention here is to respond to // "content://android.media.tv/program", not "content://android.media.tv/program/XXX". // Later, we might want to add handling of individual programs too. if (Utils.isProgramsUri(uri)) { // The given data is a programs URI. Open the Program Guide. mShowProgramGuide = true; return true; } // In case the channel is given explicitly, use it. mInitChannelUri = uri; if (DEBUG) Log.d(TAG, "ACTION_VIEW with " + mInitChannelUri); if (Channels.CONTENT_URI.equals(mInitChannelUri)) { // Tune to default channel. mInitChannelUri = null; mShouldTuneToTunerChannel = true; return true; } if ((!Utils.isChannelUriForOneChannel(mInitChannelUri) && !Utils.isChannelUriForInput(mInitChannelUri))) { Log.w(TAG, "Malformed channel uri " + mInitChannelUri + " tuning to default instead"); mInitChannelUri = null; return true; } mTuneParams = intent.getExtras(); if (mTuneParams == null) { mTuneParams = new Bundle(); } if (Utils.isChannelUriForTunerInput(mInitChannelUri)) { long channelId = ContentUris.parseId(mInitChannelUri); mTuneParams.putLong(KEY_INIT_CHANNEL_ID, channelId); } else if (TvContract.isChannelUriForPassthroughInput(mInitChannelUri)) { // If mInitChannelUri is for a passthrough TV input. String inputId = mInitChannelUri.getPathSegments().get(1); TvInputInfo input = mTvInputManagerHelper.getTvInputInfo(inputId); if (input == null) { mInitChannelUri = null; Toast.makeText(this, R.string.msg_no_specific_input, Toast.LENGTH_SHORT).show(); return false; } else if (!input.isPassthroughInput()) { mInitChannelUri = null; Toast.makeText(this, R.string.msg_not_passthrough_input, Toast.LENGTH_SHORT).show(); return false; } } else if (mInitChannelUri != null) { // Handle the URI built by TvContract.buildChannelsUriForInput(). // TODO: Change hard-coded "input" to TvContract.PARAM_INPUT. String inputId = mInitChannelUri.getQueryParameter("input"); long channelId = Utils.getLastWatchedChannelIdForInput(this, inputId); if (channelId == Channel.INVALID_ID) { String[] projection = { Channels._ID }; try (Cursor cursor = getContentResolver().query(uri, projection, null, null, null)) { if (cursor != null && cursor.moveToNext()) { channelId = cursor.getLong(0); } } } if (channelId == Channel.INVALID_ID) { // Couldn't find any channel probably because the input hasn't been set up. // Try to set it up. mInitChannelUri = null; mInputToSetUp = mTvInputManagerHelper.getTvInputInfo(inputId); } else { mInitChannelUri = TvContract.buildChannelUri(channelId); mTuneParams.putLong(KEY_INIT_CHANNEL_ID, channelId); } } } return true; }
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); }// ww w. j av 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.dwdesign.tweetings.fragment.UserProfileFragment.java
@Override public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) { if (intent == null) return;//from w w w. j a v a 2s . c om switch (requestCode) { case REQUEST_TAKE_PHOTO: { if (resultCode == Activity.RESULT_OK) { final String path = mImageUri.getPath(); final File file = path != null ? new File(path) : null; if (file != null && file.exists()) { mService.updateProfileImage(mUser.getId(), mImageUri, true); } } break; } case REQUEST_BANNER_TAKE_PHOTO: { if (resultCode == Activity.RESULT_OK) { final String path = mImageUri.getPath(); final File file = path != null ? new File(path) : null; if (file != null && file.exists()) { mService.updateBannerImage(mUser.getId(), mImageUri, true); } } break; } case REQUEST_PICK_IMAGE: { if (resultCode == Activity.RESULT_OK && intent != null) { final Uri uri = intent.getData(); final String image_path = getImagePathFromUri(getActivity(), uri); final File file = image_path != null ? new File(image_path) : null; if (file != null && file.exists()) { mService.updateProfileImage(mUser.getId(), Uri.fromFile(file), false); } } break; } case REQUEST_BANNER_PICK_IMAGE: { if (resultCode == Activity.RESULT_OK && intent != null) { final Uri uri = intent.getData(); final String image_path = getImagePathFromUri(getActivity(), uri); final File file = image_path != null ? new File(image_path) : null; if (file != null && file.exists()) { mService.updateBannerImage(mUser.getId(), Uri.fromFile(file), false); } } break; } case REQUEST_SET_COLOR: { if (resultCode == Activity.RESULT_OK && intent != null) { final int color = intent.getIntExtra(Accounts.USER_COLOR, Color.TRANSPARENT); setUserColor(getActivity(), mUserId, color); updateUserColor(); } break; } } }
From source file:com.xplink.android.carchecklist.CarCheckListActivity.java
/** Called when the activity is first created. */ @Override/*from w w w . j a v a 2 s . c o m*/ public void onCreate(Bundle savedInstanceState) { // end 480 super.onCreate(savedInstanceState); setContentView(R.layout.main); // deleteAllData(); // ************************************************************************************ listValue = restoreCheckList(); if (listValue != null) { SharedPreferences restoreShared = getSharedPreferences("mysettings", Context.MODE_PRIVATE); Editor edit = restoreShared.edit(); Map<String, Boolean> mapList = listValue.get(0); Map<String, Integer> mapSetting = listValue.get(1); int countChecknum = 0; int numPowerChecked = 0; int numEngineChecked = 0; int numExteriorChecked = 0; int numInteriorChecked = 0; int numDocumentChecked = 0; for (Map.Entry<String, Boolean> entry : mapList.entrySet()) { String[] tmp = entry.getKey().split("\\_"); Log.i("checkkeyvalue", tmp[0] + " : " + tmp[1]); String key = tmp[0]; if ("inside".equals(key)) { if (entry.getValue()) { getTotalInterior(true); numInteriorChecked++; Log.i("checkbox", "numInteriorChecked : " + numInteriorChecked); } } else if ("power".equals(key)) { if (entry.getValue()) { getTotalPower(true); numPowerChecked++; Log.i("checkbox", "numPowerChecked : " + numPowerChecked); } } else if ("engine".equals(key)) { if (entry.getValue()) { getTotalEngine(true); numEngineChecked++; Log.i("checkbox", "numEngineChecked : " + numEngineChecked); } } else if ("outside".equals(key)) { if (entry.getValue()) { getTotalExterior(true); numExteriorChecked++; Log.i("checkbox", "numExteriorChecked : " + numExteriorChecked); } } else if ("doc".equals(key)) { if (entry.getValue()) { getTotalDocument(true); numDocumentChecked++; Log.i("checkbox", "numDocumentChecked : " + numDocumentChecked); } } edit.putBoolean(entry.getKey(), entry.getValue()); // println(entry.getKey() + " : " + entry.getValue()); } Checknum = countChecknum; edit.putInt("CheckPowerTotal", numPowerChecked); edit.putInt("CheckEngineTotal", numEngineChecked); edit.putInt("CheckExteriorTotal", numExteriorChecked); edit.putInt("CheckInteriorTotal", numInteriorChecked); edit.putInt("CheckDocumentTotal", numDocumentChecked); edit.commit(); CheckPowerTotal = restoreShared.getInt("CheckPowerTotal", 0); CheckEngineTotal = restoreShared.getInt("CheckEngineTotal", 0); CheckExteriorTotal = restoreShared.getInt("CheckExteriorTotal", 0); CheckInteriorTotal = restoreShared.getInt("CheckInteriorTotal", 0); CheckDocumentTotal = restoreShared.getInt("CheckDocumentTotal", 0); Log.i("checklist", "in listValue - numPowerChecked : " + numPowerChecked); Log.i("checklist", "numEngineChecked : " + numEngineChecked); Log.i("checklist", "numExteriorChecked : " + numExteriorChecked); Log.i("checklist", "numInteriorChecked : " + numInteriorChecked); Log.i("checklist", "numDocumentChecked : " + numDocumentChecked); Log.i("checklist", "CheckPowerTotal : " + CheckPowerTotal); Log.i("checklist", "CheckEngineTotal : " + CheckEngineTotal); Log.i("checklist", "CheckExteriorTotal : " + CheckExteriorTotal); Log.i("checklist", "CheckInteriorTotal : " + CheckInteriorTotal); Log.i("checklist", "CheckDocumentTotal : " + CheckDocumentTotal); //edit.commit(); for (Map.Entry<String, Integer> entry : mapSetting.entrySet()) { if ("interior".equals(entry.getKey())) { edit.putInt("Interiorbar", entry.getValue()); } else if ("power".equals(entry.getKey())) { edit.putInt("Powerbar", entry.getValue()); } else if ("engine".equals(entry.getKey())) { edit.putInt("Enginebar", entry.getValue()); } else if ("exterior".equals(entry.getKey())) { edit.putInt("Exteriorbar", entry.getValue()); } else { edit.putInt("Documentbar", entry.getValue()); } // Log.i("checkSettingsName", "checkSettingsName : " + // entry.getKey()); } edit.commit(); /* * ProgressBar PowerProgress, EngineProgress, ExteriorProgress, * InteriorProgress, DocumentProgress, RatioProgress; TextView * percenpower, percenengine, percenexterior, perceninterior, * percendocument, Ratiotext; */ } // ************************************************************************************ // isSaveCheckBox(); store = new Bundle(); db = new DBCarCheckList(this); intent = new Intent(getApplicationContext(), RecordActivity.class); // getSettingShared(); // Log.i("dbcarchecklist", "create object DBCarCheckList"); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); float height = metrics.heightPixels; float width = metrics.widthPixels; Log.d("height", "" + height); Log.d("width", "" + width); int left195 = (int) ((width / 100) * 15.3); int left200 = (int) ((width / 100) * 16.25); int leftt200 = (int) ((width / 100) * 17); int left230 = (int) ((width / 100) * 18); int left475 = (int) ((width / 100) * 37.1); int left480 = (int) ((width / 100) * 38); int left495 = (int) ((width / 100) * 38.7); int left500 = (int) ((width / 100) * 40.5); int left510 = (int) ((width / 100) * 39.7); int left530 = (int) ((width / 100) * 41.2); int left865 = (int) ((width / 100) * 67.6); int left870 = (int) ((width / 100) * 69.5); int leftt870 = (int) ((width / 100) * 68); int leftt900 = (int) ((width / 100) * 70); int left950 = (int) ((width / 100) * 75); int left1150 = (int) ((width / 100) * 93); int left1180 = (int) ((width / 100) * 92); int top10 = (int) ((height / 100) * 3); int top20 = (int) ((height / 100) * 6.5); int top40 = (int) ((height / 100) * 5); int top95 = (int) ((height / 100) * 12); int top100 = (int) ((height / 100) * 12.5); int top110 = (int) ((height / 100) * 16.5); int top130 = (int) ((height / 100) * 19); int top135 = (int) ((height / 100) * 17.5); int top225 = (int) ((height / 100) * 28.8); int top390 = (int) ((height / 100) * 53); int top410 = (int) ((height / 100) * 51.5); int top480 = (int) ((height / 100) * 64.5); int top500 = (int) ((height / 100) * 63); int top505 = (int) ((height / 100) * 63.8); int top595 = (int) ((height / 100) * 75); int top610 = (int) ((height / 100) * 76); Intent intent = getIntent(); PercenPower = intent.getIntExtra("power", PercenPower); PercenEngine = intent.getIntExtra("engine", PercenEngine); PercenExterior = intent.getIntExtra("exterior", PercenExterior); PercenInterior = intent.getIntExtra("interior", PercenInterior); PercenDocument = intent.getIntExtra("document", PercenDocument); // follow : get data from shared preferences /* * SharedPreferences memo = getSharedPreferences("mysettings", * Context.MODE_PRIVATE); PercenPower = memo.getInt("PercenPower", 0); * PercenEngine = memo.getInt("PercenEngine", 0); PercenExterior = * memo.getInt("PercenExterior", 0); PercenInterior = * memo.getInt("PercenInterior", 0); PercenDocument = * memo.getInt("PercenDocument", 0); */ CheckPowerTotal = intent.getIntExtra("numpower", CheckPowerTotal); CheckEngineTotal = intent.getIntExtra("numengine", CheckEngineTotal); CheckExteriorTotal = intent.getIntExtra("numexterior", CheckExteriorTotal); CheckInteriorTotal = intent.getIntExtra("numinterior", CheckInteriorTotal); CheckDocumentTotal = intent.getIntExtra("numdocument", CheckDocumentTotal); // Log.d("percen", "" + PercenPower); type = Typeface.createFromAsset(getAssets(), "Circular.ttf"); MyCustomPanel view = new MyCustomPanel(this); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(1200, 800); params.width = 1200; params.height = 800; addContentView(view, params); RelativeLayout.LayoutParams imgpower = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imgpower.setMargins(left480, top20, 0, 0); RelativeLayout.LayoutParams bdpower = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); bdpower.setMargins(left475, top40, 0, 0); RelativeLayout.LayoutParams txtpower = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtpower.setMargins(left510, top135, 0, 0); ImageView borderpower = (ImageView) findViewById(R.id.powerborder); borderpower.setLayoutParams(bdpower); percenpower = (TextView) findViewById(R.id.percenpower); percenpower.setLayoutParams(txtpower); percenpower.setTypeface(type); percenpower.setText("" + PercenPower + "%"); PowerProgress = (ProgressBar) findViewById(R.id.PowerProgressbar); PowerProgress.setMax(100); PowerProgress.setProgress(PercenPower); headpower = (ImageView) findViewById(R.id.headpower); btnPower = (ImageButton) findViewById(R.id.battery_button); btnPower.setLayoutParams(imgpower); btnPower.setOnClickListener(new OnClickListener() { public void onClick(View v) { // startAnimation SlidePowerLayout(); } }); RelativeLayout.LayoutParams imgengine = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imgengine.setMargins(left200, top110, 0, 0); RelativeLayout.LayoutParams bdengine = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); bdengine.setMargins(left195, top110, 0, 0); RelativeLayout.LayoutParams txtengine = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtengine.setMargins(left230, top225, 0, 0); ImageView borderengine = (ImageView) findViewById(R.id.engineborder); borderengine.setLayoutParams(bdengine); percenengine = (TextView) findViewById(R.id.percenengine); percenengine.setLayoutParams(txtengine); percenengine.setTypeface(type); percenengine.setText("" + PercenEngine + "%"); EngineProgress = (ProgressBar) findViewById(R.id.EngineProgressbar); EngineProgress.setMax(100); EngineProgress.setProgress(PercenEngine); headengine = (ImageView) findViewById(R.id.headengine); btnEngine = (ImageButton) findViewById(R.id.engine_button); btnEngine.setLayoutParams(imgengine); btnEngine.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // startAnimation SlideEngineLayout(); } }); RelativeLayout.LayoutParams imgexterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imgexterior.setMargins(leftt200, top390, 0, 0); RelativeLayout.LayoutParams bdexterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); bdexterior.setMargins(left195, top410, 0, 0); RelativeLayout.LayoutParams txtexterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtexterior.setMargins(left230, top505, 0, 0); ImageView borderexterior = (ImageView) findViewById(R.id.exteriorborder); borderexterior.setLayoutParams(bdexterior); percenexterior = (TextView) findViewById(R.id.percenexterior); percenexterior.setLayoutParams(txtexterior); percenexterior.setTypeface(type); percenexterior.setText("" + PercenExterior + "%"); ExteriorProgress = (ProgressBar) findViewById(R.id.ExteriorProgressbar); ExteriorProgress.setMax(100); ExteriorProgress.setProgress(PercenExterior); headexterior = (ImageView) findViewById(R.id.headexterior); btnExterior = (ImageButton) findViewById(R.id.outside_button); btnExterior.setLayoutParams(imgexterior); btnExterior.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // startAnimation SlideExteriorLayout(); } }); RelativeLayout.LayoutParams imginterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imginterior.setMargins(left500, top480, 0, 0); RelativeLayout.LayoutParams bdinterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); bdinterior.setMargins(left495, top500, 0, 0); RelativeLayout.LayoutParams txtinterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtinterior.setMargins(left530, top595, 0, 0); ImageView borderinterior = (ImageView) findViewById(R.id.interiorborder); borderinterior.setLayoutParams(bdinterior); perceninterior = (TextView) findViewById(R.id.perceninterior); perceninterior.setLayoutParams(txtinterior); perceninterior.setTypeface(type); perceninterior.setText("" + PercenInterior + "%"); InteriorProgress = (ProgressBar) findViewById(R.id.InteriorProgressbar); InteriorProgress.setMax(100); InteriorProgress.setProgress(PercenInterior); headinterior = (ImageView) findViewById(R.id.headinterior); btnInterior = (ImageButton) findViewById(R.id.inside_button); btnInterior.setLayoutParams(imginterior); btnInterior.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // startAnimation SlideInteriorLayout(); } }); RelativeLayout.LayoutParams imgdocument = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imgdocument.setMargins(left870, top480, 0, 0); RelativeLayout.LayoutParams bddocument = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); bddocument.setMargins(left865, top500, 0, 0); RelativeLayout.LayoutParams txtdocument = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtdocument.setMargins(leftt900, top595, 0, 0); RelativeLayout.LayoutParams progdocument = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); progdocument.setMargins(leftt870, top610, 0, 0); ImageView borderdocument = (ImageView) findViewById(R.id.documentborder); borderdocument.setLayoutParams(bddocument); percendocument = (TextView) findViewById(R.id.percendocument); percendocument.setLayoutParams(txtdocument); percendocument.setTypeface(type); percendocument.setText("" + PercenDocument + "%"); DocumentProgress = (ProgressBar) findViewById(R.id.DocumentProgressbar); DocumentProgress.setMax(100); DocumentProgress.setProgress(PercenDocument); headdocument = (ImageView) findViewById(R.id.headdocument); btnDocument = (ImageButton) findViewById(R.id.document_button); btnDocument.setLayoutParams(imgdocument); btnDocument.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SlideDocumentLayout(); } }); RelativeLayout.LayoutParams imgsetting = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imgsetting.setMargins(left1180, top10, 0, 0); RelativeLayout.LayoutParams txtratio = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtratio.setMargins(left950, top95, 0, 0); RelativeLayout.LayoutParams ratioprog = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); ratioprog.setMargins(left1150, top100, 0, 0); Ratiotext = (TextView) findViewById(R.id.ratiotext); Ratiotext.setLayoutParams(txtratio); RatioProgress = (ProgressBar) findViewById(R.id.ratio); RatioProgress.setLayoutParams(ratioprog); RatioProgress.setMax(100); headsetting = (ImageView) findViewById(R.id.headsetting); btnSetting = (ImageButton) findViewById(R.id.setting_button); btnSetting.setLayoutParams(imgsetting); btnSetting.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SlideSettingLayout(); } }); // addMob LinearLayout layout = (LinearLayout) findViewById(R.id.admob); adView = new AdView(getApplicationContext()); adView.setAdSize(AdSize.LEADERBOARD); adView.setAdUnitId(admonId); //adView.setAdUnitId("C17E5F3A146EC7E805175C72634D8098"); // Add the adView to it layout.addView(adView); // Initiate a generic request to load it with an ad AdRequest.Builder adRequestBuilder = new AdRequest.Builder(); adRequestBuilder.addTestDevice("C17E5F3A146EC7E805175C72634D8098"); // adRequestBuilder.addTestDevice("9F5DF3C9768A51CB506B68902F766B40"); adView.loadAd(adRequestBuilder.build()); // adView.loadAd(new AdRequest.Builder().build()); SharedPreferences shared = getSharedPreferences("mysettings", Context.MODE_PRIVATE); // Log.i("checksum", // "before call CheckRatio : " + shared.getInt("checknum", 0)); CheckRatio(); // Log.i("checklist", "checking percenpower : " + // shared.getInt("PercenPower", -1)); // restoreProgressCheckList(); }
From source file:com.ichi2.anki2.DeckPicker.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); mDontSaveOnStop = false;//from ww w .j a va 2 s . c o m if (resultCode == RESULT_MEDIA_EJECTED) { showDialog(DIALOG_SD_CARD_NOT_MOUNTED); return; } else if (resultCode == RESULT_DB_ERROR) { handleDbError(); return; } if (requestCode == SHOW_STUDYOPTIONS && resultCode == RESULT_OK) { loadCounts(); } else if (requestCode == ADD_NOTE && resultCode != RESULT_CANCELED) { loadCounts(); } else if (requestCode == BROWSE_CARDS && (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED)) { loadCounts(); } else if (requestCode == ADD_CRAM_DECK) { // TODO: check, if ok has been clicked loadCounts(); } else if (requestCode == REPORT_ERROR) { showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 4); } else if (requestCode == SHOW_INFO_UPGRADE_DECKS) { if (intent != null && intent.hasExtra(Info.TYPE_UPGRADE_STAGE)) { int type = intent.getIntExtra(Info.TYPE_UPGRADE_STAGE, Info.UPGRADE_SCREEN_BASIC1); if (type == Info.UPGRADE_CONTINUE) { showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 3); } else { showUpgradeScreen(true, type, !intent.hasExtra(Info.TYPE_ANIMATION_RIGHT)); } } else { if (resultCode == RESULT_OK) { if (mOpenCollectionDialog != null && mOpenCollectionDialog.isShowing()) { mOpenCollectionDialog.dismiss(); } if (AnkiDroidApp.colIsOpen()) { AnkiDroidApp.closeCollection(true); } AnkiDroidApp.openCollection(AnkiDroidApp.getCollectionPath()); loadCounts(); } else { finishWithAnimation(); } } } else if (requestCode == SHOW_INFO_WELCOME || requestCode == SHOW_INFO_NEW_VERSION) { if (resultCode == RESULT_OK) { showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), requestCode == SHOW_INFO_WELCOME ? 1 : 2); } else { finishWithAnimation(); } } else if (requestCode == PREFERENCES_UPDATE) { String oldPath = mPrefDeckPath; SharedPreferences pref = restorePreferences(); String newLanguage = pref.getString("language", ""); if (!AnkiDroidApp.getLanguage().equals(newLanguage)) { AnkiDroidApp.setLanguage(newLanguage); mInvalidateMenu = true; } if (mNotMountedDialog != null && mNotMountedDialog.isShowing() && pref.getBoolean("internalMemory", false)) { showStartupScreensAndDialogs(pref, 0); } else if (!mPrefDeckPath.equals(oldPath)) { loadCollection(); } // if (resultCode == StudyOptions.RESULT_RESTART) { // setResult(StudyOptions.RESULT_RESTART); // finishWithAnimation(); // } else { // SharedPreferences preferences = PrefSettings.getSharedPrefs(getBaseContext()); // BackupManager.initBackup(); // if (!mPrefDeckPath.equals(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory())) || // mPrefDeckOrder != Integer.parseInt(preferences.getString("deckOrder", "0"))) { // // populateDeckList(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory())); // } // } } else if (requestCode == REPORT_FEEDBACK && resultCode == RESULT_OK) { } else if (requestCode == LOG_IN_FOR_SYNC && resultCode == RESULT_OK) { sync(); } else if (requestCode == LOG_IN_FOR_SHARED_DECK && resultCode == RESULT_OK) { addSharedDeck(); } else if (requestCode == ADD_SHARED_DECKS) { if (intent != null) { mImportPath = intent.getStringExtra("importPath"); } if (AnkiDroidApp.colIsOpen() && mImportPath != null) { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener, new TaskData(AnkiDroidApp.getCol(), mImportPath, true)); mImportPath = null; } } else if (requestCode == REQUEST_REVIEW) { Log.i(AnkiDroidApp.TAG, "Result code = " + resultCode); switch (resultCode) { default: // do not reload counts, if activity is created anew because it has been before destroyed by android loadCounts(); break; case Reviewer.RESULT_NO_MORE_CARDS: mDontSaveOnStop = true; Intent i = new Intent(); i.setClass(this, StudyOptionsActivity.class); i.putExtra("onlyFnsMsg", true); startActivityForResult(i, SHOW_STUDYOPTIONS); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT); } break; } } // workaround for hidden dialog on return BroadcastMessages.showDialog(); }
From source file:de.quist.app.errorreporter.ExceptionReportService.java
private void sendReport(Intent intent) throws UnsupportedEncodingException, NameNotFoundException { Log.v(TAG, "Got request to report error: " + intent.toString()); Uri server = getTargetUrl();//from ww w. ja v a 2s.co m boolean isManualReport = intent.getBooleanExtra(EXTRA_MANUAL_REPORT, false); boolean isReportOnFroyo = isReportOnFroyo(); boolean isFroyoOrAbove = isFroyoOrAbove(); if (isFroyoOrAbove && !isManualReport && !isReportOnFroyo) { // We don't send automatic reports on froyo or above Log.d(TAG, "Don't send automatic report on froyo"); return; } Set<String> fieldsToSend = getFieldsToSend(); String stacktrace = intent.getStringExtra(EXTRA_STACK_TRACE); String exception = intent.getStringExtra(EXTRA_EXCEPTION_CLASS); String message = intent.getStringExtra(EXTRA_MESSAGE); long availableMemory = intent.getLongExtra(EXTRA_AVAILABLE_MEMORY, -1l); long totalMemory = intent.getLongExtra(EXTRA_TOTAL_MEMORY, -1l); String dateTime = intent.getStringExtra(EXTRA_EXCEPTION_TIME); String threadName = intent.getStringExtra(EXTRA_THREAD_NAME); String extraMessage = intent.getStringExtra(EXTRA_EXTRA_MESSAGE); List<NameValuePair> params = new ArrayList<NameValuePair>(); addNameValuePair(params, fieldsToSend, "exStackTrace", stacktrace); addNameValuePair(params, fieldsToSend, "exClass", exception); addNameValuePair(params, fieldsToSend, "exDateTime", dateTime); addNameValuePair(params, fieldsToSend, "exMessage", message); addNameValuePair(params, fieldsToSend, "exThreadName", threadName); if (extraMessage != null) addNameValuePair(params, fieldsToSend, "extraMessage", extraMessage); if (availableMemory >= 0) addNameValuePair(params, fieldsToSend, "devAvailableMemory", availableMemory + ""); if (totalMemory >= 0) addNameValuePair(params, fieldsToSend, "devTotalMemory", totalMemory + ""); PackageManager pm = getPackageManager(); try { PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0); addNameValuePair(params, fieldsToSend, "appVersionCode", packageInfo.versionCode + ""); addNameValuePair(params, fieldsToSend, "appVersionName", packageInfo.versionName); addNameValuePair(params, fieldsToSend, "appPackageName", packageInfo.packageName); } catch (NameNotFoundException e) { } addNameValuePair(params, fieldsToSend, "devModel", android.os.Build.MODEL); addNameValuePair(params, fieldsToSend, "devSdk", android.os.Build.VERSION.SDK); addNameValuePair(params, fieldsToSend, "devReleaseVersion", android.os.Build.VERSION.RELEASE); HttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(server.toString()); post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); Log.d(TAG, "Created post request"); try { httpClient.execute(post); Log.v(TAG, "Reported error: " + intent.toString()); } catch (ClientProtocolException e) { // Ignore this kind of error Log.e(TAG, "Error while sending an error report", e); } catch (SSLException e) { Log.e(TAG, "Error while sending an error report", e); } catch (IOException e) { if (e instanceof SocketException && e.getMessage().contains("Permission denied")) { Log.e(TAG, "You don't have internet permission", e); } else { int maximumRetryCount = getMaximumRetryCount(); int maximumExponent = getMaximumBackoffExponent(); // Retry at a later point in time AlarmManager alarmMgr = (AlarmManager) getSystemService(ALARM_SERVICE); int exponent = intent.getIntExtra(EXTRA_CURRENT_RETRY_COUNT, 0); intent.putExtra(EXTRA_CURRENT_RETRY_COUNT, exponent + 1); PendingIntent operation = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); if (exponent >= maximumRetryCount) { // Discard error Log.w(TAG, "Error report reached the maximum retry count and will be discarded.\nStacktrace:\n" + stacktrace); return; } if (exponent > maximumExponent) { exponent = maximumExponent; } long backoff = (1 << exponent) * 1000; // backoff in ms alarmMgr.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + backoff, operation); } } }
From source file:com.cpjd.roblu.ui.images.ImageGalleryActivity.java
/** * Receives the picture that was taken by the user * @param requestCode the request code of the child activity * @param resultCode the result code of the child activity * @param data the picture that was taken */// w w w. j av a2 s. co m @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == Constants.GENERAL && resultCode == FragmentActivity.RESULT_OK) { // fetch file from storage Bitmap bitmap = BitmapFactory.decodeFile(tempPictureFile.getPath()); // fix rotation try { ExifInterface ei = new ExifInterface(tempPictureFile.getPath()); int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: bitmap = rotateImage(bitmap, 90); break; case ExifInterface.ORIENTATION_ROTATE_180: bitmap = rotateImage(bitmap, 180); break; case ExifInterface.ORIENTATION_ROTATE_270: bitmap = rotateImage(bitmap, 270); break; default: break; } } catch (IOException e) { Log.d("RBS", "Failed to remove EXIF rotation data from the picture."); } /* * Convert the image into a byte[] and save it to the gallery */ // Convert the bitmap to a byte array ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 30, stream); byte[] array = stream.toByteArray(); int newID = new IO(getApplicationContext()).savePicture(eventID, array); // Add the image to the current array if (IMAGES == null) IMAGES = new ArrayList<>(); IMAGES.add(array); // save the ID to the gallery for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) { if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) { if (((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)) .getPictureIDs() == null) { ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)) .setPictureIDs(new ArrayList<Integer>()); } ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).getPictureIDs() .add(newID); break; } } TeamViewer.team.setLastEdit(System.currentTimeMillis()); new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team); imageGalleryAdapter.notifyDataSetChanged(); } /* * User edited an image */ else if (resultCode == Constants.IMAGE_EDITED) { TeamViewer.team.setLastEdit(System.currentTimeMillis()); /* * Update the image in the gallery */ for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) { if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) { if (((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)) .getPictureIDs() == null) { ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)) .setPictureIDs(new ArrayList<Integer>()); } ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).getPictureIDs() .add(new IO(getApplicationContext()).savePicture(eventID, IMAGES.get(data.getIntExtra("position", 0)))); break; } } new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team); imageGalleryAdapter.notifyDataSetChanged(); } /* * User deleted an image */ else if (resultCode == Constants.IMAGE_DELETED) { // Remove the image from the gallery ID list for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) { if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) { int pictureID = ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)) .getPictureIDs().remove(data.getIntExtra("position", 0)); // delete from file system new IO(getApplicationContext()).deletePicture(eventID, pictureID); break; } } IMAGES.remove(data.getIntExtra("position", 0)); imageGalleryAdapter.notifyDataSetChanged(); TeamViewer.team.setLastEdit(System.currentTimeMillis()); new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team); } }