Example usage for android.content Intent getIntExtra

List of usage examples for android.content Intent getIntExtra

Introduction

In this page you can find the example usage for android.content Intent getIntExtra.

Prototype

public int getIntExtra(String name, int defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.chocopepper.chococam.activity.friends.manage.FriendsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.friends);/*from   w ww.j a  va2 s. c  o  m*/

    sharedPref = getSharedPreferences(Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
    selectedPagerIndex = sharedPref.getInt(PAGER_INDEX, VIEW_FRIENDLIST);

    ImageView btnCreatechat = (ImageView) findViewById(R.id.btnCreateChat);
    btnCreatechat.setVisibility(View.GONE);

    TextView txt_title = (TextView) findViewById(R.id.title);
    txt_title.setText(R.string.friends_tab_sub_suggestion);

    List<Fragment> fragments = new Vector<Fragment>();

    final Fragment frFreindsList = Fragment.instantiate(this, FriendsList.class.getName());

    Intent i = getIntent();
    long target_user_id = i.getLongExtra(Constants.TARGET_USER_ID,
            UserService.getDefaultUserId(FriendsActivity.this));
    Bundle args = new Bundle();
    args.putLong(Constants.TARGET_USER_ID, target_user_id);

    selectedPagerIndex = i.getIntExtra(PAGER_INDEX, selectedPagerIndex);

    frFreindsList.setArguments(args);
    fragments.add(frFreindsList);
    //fragments.add(Fragment.instantiate(this, FriendsList.class.getName()));

    fragments.add(Fragment.instantiate(this, RecommendedFriends.class.getName()));
    fragments.add(Fragment.instantiate(this, ReceivedRequests.class.getName()));

    btnEdit = (RelativeLayout) findViewById(R.id.btnEdit);
    btnEdit.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // ? ? ?   ?
            ((FriendsList) frFreindsList).switchEditMode();
        }
    });

    mAdapter = new FriendsAdapter(getSupportFragmentManager(), fragments);
    mAdapter.addTitle(this.getString(R.string.friends_tab_sub_current_friends));
    mAdapter.addTitle(this.getString(R.string.friends_tab_sub_suggestion));
    //mAdapter.addTitle(this.getString(R.string.friends_tab_sub_invitation));
    mAdapter.addTitle(this.getString(R.string.friends_tab_sub_received_invitation));

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAdapter);

    //  .
    mViewPager.setCurrentItem(selectedPagerIndex);
    // 2012-05-23 brucewang
    if (selectedPagerIndex == 0) {
        btnEdit.setVisibility(View.VISIBLE);
    }

    //mIndicator = (TitlePageIndicator)findViewById(R.id.indicator);
    //        mIndicator = (ViewPagerIndicator)findViewById(R.id.indicator);
    //      mIndicator.addPageChangeListener(this);
    //        mViewPager.setOnPageChangeListener(mIndicator);

    indicator = (TitlePageIndicator) findViewById(R.id.indicator);
    indicator.setFooterIndicatorStyle(IndicatorStyle.None);
    indicator.setViewPager(mViewPager, selectedPagerIndex);
    indicator.setOnPageChangeListener(this);
    mViewPager.setOnPageChangeListener(indicator);

}

From source file:com.android.contacts.SimImportService.java

private ImportTask createTaskForIntent(Intent intent, int startId) {
    final AccountWithDataSet targetAccount = intent.getParcelableExtra(EXTRA_ACCOUNT);
    final ArrayList<SimContact> contacts = intent.getParcelableArrayListExtra(EXTRA_SIM_CONTACTS);

    final int subscriptionId = intent.getIntExtra(EXTRA_SIM_SUBSCRIPTION_ID, SimCard.NO_SUBSCRIPTION_ID);
    final SimContactDao dao = SimContactDao.create(this);
    final SimCard sim = dao.getSimBySubscriptionId(subscriptionId);
    if (sim != null) {
        return new ImportTask(sim, contacts, targetAccount, dao, startId);
    } else {//from   ww  w .  j a v  a2s. co  m
        return null;
    }
}

From source file:com.appsimobile.appsii.module.calls.CallLogLoader.java

/**
 * Handles a request to start the Loader.
 *//*from   www  .  j  a v  a2  s. c o m*/
@Override
protected void onStartLoading() {
    AppInjector.inject(this);
    if (mCallLogEntries != null) {
        // If we currently have a result available, deliver it
        // immediately.
        deliverResult(mCallLogEntries);
    }

    // Start watching for changes in the app data.
    if (mCallLogObserver == null) {
        mCallLogObserver = new ContentObserver(new Handler()) {
            @Override
            public void onChange(boolean selfChange) {
                onChange(selfChange, null);
            }

            @Override
            public void onChange(boolean selfChange, Uri uri) {
                onContentChanged();
            }
        };
        getContext().getContentResolver().registerContentObserver(CallLog.Calls.CONTENT_URI, true,
                mCallLogObserver);
    }

    mPermissionGrantedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int req = intent.getIntExtra(PermissionUtils.EXTRA_REQUEST_CODE, 0);
            if (req == PermissionUtils.REQUEST_CODE_PERMISSION_READ_CALL_LOG) {
                onContentChanged();
            }
        }
    };
    IntentFilter filter2 = new IntentFilter(PermissionUtils.ACTION_PERMISSION_RESULT);
    getContext().registerReceiver(mPermissionGrantedReceiver, filter2);

    // Has something interesting in the configuration changed since we
    // last built the app list?

    if (takeContentChanged() || mCallLogEntries == null) {
        // If the data has changed since the last time it was loaded
        // or is not currently available, start a load.
        forceLoad();
    }
}

From source file:au.com.wallaceit.reddinator.Rservice.java

public ListRemoteViewsFactory(Context context, Intent intent) {
    this.mContext = context;
    appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
            AppWidgetManager.INVALID_APPWIDGET_ID);
    global = ((GlobalObjects) context.getApplicationContext());
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    //System.out.println("New view factory created for widget ID:"+appWidgetId);
    // Set thread network policy to prevent network on main thread exceptions.
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);/*from   www.j  a v  a2  s  .  c  o  m*/
    // if this is a user request (apart from 'loadmore') or an auto update, do not attempt to load cache.
    // when a user clicks load more and a new view factory needs to be created we don't want to bypass cache, we want to load the cached items
    int loadType = global.getLoadType();
    if (!global.getBypassCache() || loadType == GlobalObjects.LOADTYPE_LOADMORE) {
        // load cached data
        data = global.getFeed(mSharedPreferences, appWidgetId);
        if (data.length() != 0) {
            titleFontSize = mSharedPreferences.getString(context.getString(R.string.widget_theme_pref), "16");
            try {
                lastItemId = data.getJSONObject(data.length() - 1).getJSONObject("data").getString("name");
            } catch (JSONException e) {
                lastItemId = "0"; // Could not get last item ID; perform a reload next time and show error view :(
                e.printStackTrace();
            }
            if (loadType == GlobalObjects.LOADTYPE_LOAD) {
                loadCached = true; // this isn't a loadmore request, the cache is loaded and we're done
                //System.out.println("Cache loaded, no user request received.");
            }
        } else {
            loadReddits(false); // No feed items; do a reload.
        }
    } else {
        data = new JSONArray(); // set empty data to prevent any NPE
    }
}

From source file:net.olejon.mdapp.NotesEditActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Intent//from  ww w  .j  a v a  2 s .com
    final Intent intent = getIntent();

    final String noteTitle = intent.getStringExtra("title");

    noteId = intent.getIntExtra("id", 0);

    // Layout
    setContentView(R.layout.activity_notes_edit);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.notes_edit_toolbar);

    final String title = (noteId == 0) ? getString(R.string.notes_edit_title_new)
            : getString(R.string.notes_edit_title_edit);

    toolbar.setTitle(title);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Elements
    mTitleEditText = (EditText) findViewById(R.id.notes_edit_title);
    mTextEditText = (EditText) findViewById(R.id.notes_edit_text);
    mPatientIdEditText = (EditText) findViewById(R.id.notes_edit_patient_id);
    mPatientNameEditText = (EditText) findViewById(R.id.notes_edit_patient_name);
    mPatientDoctorEditText = (EditText) findViewById(R.id.notes_edit_patient_doctor);
    mPatientDepartmentEditText = (EditText) findViewById(R.id.notes_edit_patient_department);
    mPatientRoomEditText = (EditText) findViewById(R.id.notes_edit_patient_room);
    mPatientMedicationsTextView = (TextView) findViewById(R.id.notes_edit_patient_medications);

    if (noteTitle != null && !noteTitle.equals(""))
        mTitleEditText.setText(noteTitle);

    Button patientAddMedicationButton = (Button) findViewById(R.id.notes_edit_patient_add_medication);

    patientAddMedicationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(mContext, NotesEditMedicationsActivity.class);
            startActivityForResult(intent, MEDICATION_REQUEST_CODE);
        }
    });

    // Note
    getNote();
}

From source file:com.android.deskclock2.DeskClock.java

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setVolumeControlStream(AudioManager.STREAM_ALARM);

    if (icicle != null) {
        mSelectedTab = icicle.getInt(KEY_SELECTED_TAB, CLOCK_TAB_INDEX);
    } else {//  w ww.  ja v  a  2s  .  c om
        mSelectedTab = CLOCK_TAB_INDEX;

        // Set the background color to initially match the theme value so that we can
        // smoothly transition to the dynamic color.
        setBackgroundColor(getResources().getColor(R.color.default_background), false /* animate */);
    }

    // Honor the tab requested by the intent, if any.
    final Intent intent = getIntent();
    if (intent != null) {
        int tab = intent.getIntExtra(SELECT_TAB_INTENT_EXTRA, -1);
        if (tab != -1) {
            mSelectedTab = tab;
        }
    }

    setContentView(R.layout.desk_clock);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    mFab = (ImageView) findViewById(R.id.fab);
    mLeftButton = (ImageButton) findViewById(R.id.left_button);
    mRightButton = (ImageButton) findViewById(R.id.right_button);
    if (mTabsAdapter == null) {
        mViewPager = (RtlViewPager) findViewById(R.id.desk_clock_pager);
        // Keep all four tabs to minimize jank.
        mViewPager.setOffscreenPageLimit(3);
        // Set Accessibility Delegate to null so ViewPager doesn't intercept movements and
        // prevent the fab from being selected.
        mViewPager.setAccessibilityDelegate(null);
        mTabsAdapter = new TabsAdapter(this, mViewPager);
        createTabs();
        mTabLayout.setOnTabSelectedListener(new ViewPagerOnTabSelectedListener(mViewPager));
    }

    mFab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedFragment().onFabClick(view);
        }
    });
    mLeftButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedFragment().onLeftButtonClick(view);
        }
    });
    mRightButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedFragment().onRightButtonClick(view);
        }
    });

    // Configure the menu item controllers.
    mActionBarMenuManager.addMenuItemController(new SettingMenuItemController(this))
            .addMenuItemController(new NightModeMenuItemController(this))
            .addMenuItemController(MenuItemControllerFactory.getInstance().buildMenuItemControllers(this));

    // Inflate the menu during creation to avoid a double layout pass. Otherwise, the menu
    // inflation occurs *after* the initial draw and a second layout pass adds in the menu.
    onCreateOptionsMenu(toolbar.getMenu());

    // We need to update the system next alarm time on app startup because the
    // user might have clear our data.
    AlarmStateManager.updateNextAlarm(this);
}

From source file:com.android.example.wordlistloader.MainActivity.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == WORD_EDIT) {
        if (resultCode == RESULT_OK) {
            String word = data.getStringExtra(EditWordActivity.EXTRA_REPLY);

            // Update the database
            if (!TextUtils.isEmpty(word)) {
                ContentValues values = new ContentValues();
                values.put("word", word);
                int id = data.getIntExtra(WordListAdapter.EXTRA_ID, -99);

                if (id == WORD_ADD) {
                    getContentResolver().insert(CONTENT_URI, values);
                } else if (id >= 0) {
                    String[] selectionArgs = { Integer.toString(id) };
                    getContentResolver().update(CONTENT_URI, values, KEY_ID, selectionArgs);
                }//w  ww.j a  v  a  2s.  c  o m
                // Update the UI (The loader should do this for us, now, when the data is ready.
                // But the loader does not get called. And so the data does not get set...
                // This is a known issue, and restarting the loader is the solution.
                // mAdapter.notifyDataSetChanged();
                getSupportLoaderManager().restartLoader(0, null, this);
            } else {
                Toast.makeText(getApplicationContext(), R.string.empty_word_not_saved, Toast.LENGTH_LONG)
                        .show();
            }
        }
    }
}

From source file:es.uma.lcc.lockpic.MainActivity.java

private void encryptImage(Intent data) {
    String src = data.getStringExtra("path");
    int width = data.getIntExtra("width", 0);
    int height = data.getIntExtra("height", 0);
    (new EncryptionUploaderTask(src, width, height, data.getStringArrayListExtra("rectangles"),
            MainActivity.this)).execute();
}

From source file:net.niyonkuru.koodroid.service.SessionService.java

@Override
public void onHandleIntent(Intent intent) {
    if (DEBUG)/*  www . jav  a2 s .  co m*/
        Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")");

    int request = intent.getIntExtra(EXTRA_REQUEST, REQUEST_LOGIN);
    if (request == REQUEST_LOGOUT) {
        logout();
        return;
    }

    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);

    final String email = intent.getStringExtra(EXTRA_EMAIL);
    final String password = intent.getStringExtra(EXTRA_PASSWORD);
    boolean broadcast = intent.getBooleanExtra(EXTRA_BROADCAST, false);

    /* totally ignore this request until full credentials are provided */
    if (email == null || password == null)
        return;

    final long startLogin = System.currentTimeMillis();
    final long lastLogin = mSettings.lastLogin();

    /* if the last successful login is within the last 15 minutes */
    if (startLogin - lastLogin <= DateUtils.MINUTE_IN_MILLIS * 15) {

        /* do a credentials check again the local data store */
        if (email.equals(mSettings.email()) && password.equals(mSettings.password())) {
            if (broadcast)
                IntentUtils.callWidget(this, LOGIN_FINISHED);
            announce(receiver, STATUS_FINISHED);
            return;
        }
    }

    try {
        if (NetworkUtils.isConnected(this)) {
            /* announce to the caller that we are now running */
            announce(receiver, STATUS_RUNNING);

        } else
            throw new ServiceException(getString(R.string.error_network_down));

        if (mSettings.email() == null) {
            /* this is likely a new user */
            Crittercism.leaveBreadcrumb(TAG + ": first_time_login");
        }

        login(email, password);
        saveCookies();

        if (DEBUG)
            Log.d(TAG, "login took " + (System.currentTimeMillis() - startLogin) + "ms");

    } catch (IOException e) {
        if (DEBUG)
            Log.e(TAG, "Problem while logging in", e);

        /* if the exception was simply from an abort */
        if (mPostRequest != null && mPostRequest.isAborted())
            return;

        if (receiver != null) {
            // Pass back error to surface listener
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
        return; /* do not announce success below */
    }

    if (broadcast)
        IntentUtils.callWidget(this, LOGIN_FINISHED);
    announce(receiver, STATUS_FINISHED);
}

From source file:com.ayaseya.padnotification.GcmIntentService.java

@Override
public void onCreate() {
    super.onCreate();

    ringerMode = false;/*from w w w  .java  2 s  .  c o  m*/
    silentMode = false;
    vibrateMode = false;

    isPlugged = false;

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    checkbox_sound = sharedPreferences.getBoolean("checkbox_sound_key", true);
    checkbox_vibration = sharedPreferences.getBoolean("checkbox_vibration_key", false);

    Set<String> multiValues = sharedPreferences.getStringSet("list_preference", null);
    ArrayList<String> timeZone = new ArrayList<String>();

    if (multiValues != null) {

        timeZone.addAll(multiValues);
        Collections.sort(timeZone);
        for (int i = 0; i < timeZone.size(); i++) {
            //            Log.v(TAG, "TimeZone=" + timeZone.get(i));
        }

        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        if (timeZone.indexOf(String.valueOf(hour)) == -1) {
            notificationPermission = false;
            Log.v(TAG, "?????????");
        } else {
            notificationPermission = true;
            Log.v(TAG, "??????");
        }
    }

    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    ringerModeStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_NORMAL) {
                    // 
                    ringerMode = true;
                } else {
                    ringerMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE,
                        -1) == AudioManager.RINGER_MODE_VIBRATE) {
                    // 
                    vibrateMode = true;

                } else {

                    vibrateMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_SILENT) {
                    // 
                    silentMode = true;

                } else {

                    silentMode = false;

                }
            }
        }
    };

    plugStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getIntExtra("state", 0) > 0) {
                isPlugged = true;
                //               Log.v(TAG, "IN");
            } else {
                isPlugged = false;
                //               Log.v(TAG, "OUT");
            }
        }
    };

    // Broadcast Receiver???
    registerReceiver(plugStateChangeReceiver, plugIntentFilter);
    registerReceiver(ringerModeStateChangeReceiver, ringerModeIntentFilter);
}