Java Code Examples for android.content.Intent#getIntExtra()

The following examples show how to use android.content.Intent#getIntExtra() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	setContentView(R.layout.topic_detail);
	ActionBar actionBar = getActionBar();
	actionBar.setIcon(null);
	actionBar.setDisplayHomeAsUpEnabled(true);
	actionBar.setDisplayUseLogoEnabled(false);
	actionBar.show();
	Intent intent = getIntent();
	String topic_id = intent.getStringExtra("topic_id");
	int isFocus= intent.getIntExtra("isFocus", 10);
	dm = getResources().getDisplayMetrics();
	ViewPager pager = (ViewPager) findViewById(R.id.pager);
	tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
	pager.setAdapter(new TopicDetailAdapter(getSupportFragmentManager(),topic_id,isFocus));
	tabs.setViewPager(pager);
	setTabsValue();
}
 
Example 2
Source Project: Synapse   File: MainService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    @Action final int action = intent.getIntExtra(ACTION_KEY, -1);

    if (isIdle()) {
        switch (action) {
            case ACTION_DOWNLOAD:
                downloadFiles();
                checkAndAddDemoModel();
                break;

            case ACTION_TRAIN:
                handleTraining(intent);
                break;

            case IDLE:
            default:
                throw new UnsupportedOperationException();
        }

        mAction = action;
    }

    return super.onStartCommand(intent, flags, startId);
}
 
Example 3
@Override
public void onDeviceSelected(@NonNull final BluetoothDevice device, final String name) {
	final Intent intent = getIntent();
	final String overwrittenName = intent.getStringExtra(DfuService.EXTRA_DEVICE_NAME);
	final String path = intent.getStringExtra(DfuService.EXTRA_FILE_PATH);
	final String initPath = intent.getStringExtra(DfuService.EXTRA_INIT_FILE_PATH);
	final String address = device.getAddress();
	final String finalName = overwrittenName == null ? (name != null ? name : getString(R.string.not_available)) : overwrittenName;
	final int type = intent.getIntExtra(DfuService.EXTRA_FILE_TYPE, DfuService.TYPE_AUTO);
	final boolean keepBond = intent.getBooleanExtra(DfuService.EXTRA_KEEP_BOND, false);

	// Start DFU service with data provided in the intent
	final Intent service = new Intent(this, DfuService.class);
	service.putExtra(DfuService.EXTRA_DEVICE_ADDRESS, address);
	service.putExtra(DfuService.EXTRA_DEVICE_NAME, finalName);
	service.putExtra(DfuService.EXTRA_FILE_TYPE, type);
	service.putExtra(DfuService.EXTRA_FILE_PATH, path);
	if (intent.hasExtra(DfuService.EXTRA_INIT_FILE_PATH))
		service.putExtra(DfuService.EXTRA_INIT_FILE_PATH, initPath);
	service.putExtra(DfuService.EXTRA_KEEP_BOND, keepBond);
	service.putExtra(DfuService.EXTRA_UNSAFE_EXPERIMENTAL_BUTTONLESS_DFU, true);
	startService(service);
	finish();
}
 
Example 4
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    final BluetoothDevice bondDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

    if (mBluetoothGatt != null && mBluetoothGatt.getDevice() != null && bondDevice != null) {
        if (!bondDevice.getAddress().equals(mBluetoothGatt.getDevice().getAddress())) {
            Log.d(TAG, "Bond state wrong device");
            return; // That wasnt a device we care about!!
        }
    }

    if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
        final int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
        if (state == BluetoothDevice.BOND_BONDED) {
            authenticateConnection();
        }
    }
}
 
Example 5
/**
 * Get the device's current battery level (as a percentage of total).
 *
 * @return the device's current battery level (as a percentage of total), or null if unknown
 */
private @Nullable Float getBatteryLevel(final @NotNull Intent batteryIntent) {
  try {
    int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

    if (level == -1 || scale == -1) {
      return null;
    }

    float percentMultiplier = 100.0f;

    return ((float) level / (float) scale) * percentMultiplier;
  } catch (Exception e) {
    logger.log(SentryLevel.ERROR, "Error getting device battery level.", e);
    return null;
  }
}
 
Example 6
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
        int state = intent.getIntExtra("state", -1);
        switch (state) {
            case 0:
                if (player.isPlaying()) {
                    Log.d(LOG_TAG, "Chat, pausing from headsetPlug");
                    showVideoInterface();
                    pauseStream();
                }
                break;
            case 1:
                showVideoInterface();
                break;
            default:

        }
    }
}
 
Example 7
Source Project: XMouse   File: ListEditActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_edit);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    layoutInflater = getLayoutInflater();

    Intent mIntent = getIntent();
    int intValue = mIntent.getIntExtra("intVariableType", 0);


    if(intValue==0){ //hosts
        type = ActivityType.type_host;
        setTitle("Manage Hosts");
    }else if(intValue ==1){ //scripts
        type=ActivityType.type_script;
        setTitle("Manage Scripts");
    }

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show();
            xMouseManage(null);
        }
    });

    mList = (ListView) findViewById(R.id.myListView);
    if(MainActivity.db!=null) {
        loadCurrentHostList();
    }

}
 
Example 8
@Override
public void onReceive(Context context, Intent intent) {
    int pageNumber = intent.getIntExtra(AppConstants.Highlight.PAGE_NUMBER, -1);
    int ayaNumber = intent.getIntExtra(AppConstants.Highlight.VERSE_NUMBER, -1);
    int soraNumber = intent.getIntExtra(AppConstants.Highlight.SORA_NUMBER, -1);
  //  Toast.makeText(getContext(),"okddd"+ pageNumber, Toast.LENGTH_LONG).show();

    if (pageNumber != -1
            && ayaNumber != -1
            && soraNumber != -1
            && getArguments().getInt(AppConstants.Highlight.ARG_SECTION_NUMBER) == 604 - pageNumber
            && soraCurrentPage == QuranPageReadActivity.selectPage) {

        Log.d("Locations", soraCurrentPage + " : " + pageNumber + "---" + ayaNumber + "---" + soraNumber);

        if (QuranPageFragment.this.getResources().getConfiguration().
                orientation == Configuration.ORIENTATION_LANDSCAPE) {
            quranImageLandscapeWeak.get().mRects.clear();
            quranImageLandscapeWeak.get().mRects.addAll(new DatabaseAccess().getAyaRectsMap(pageNumber,
                    soraNumber,
                    ayaNumber));
            quranImageLandscapeWeak.get().postInvalidate();
        } else {
            quranImagePortraitWeak.get().mRects.clear();
            quranImagePortraitWeak.get().mRects.addAll(new DatabaseAccess().getAyaRectsMap(pageNumber,
                    soraNumber,
                    ayaNumber));
            quranImagePortraitWeak.get().postInvalidate();
        }

    }
}
 
Example 9
private void handleSelectPlayersResult(int response, Intent data) {
  if (response != Activity.RESULT_OK) {
    Log.w(TAG, "*** select players UI cancelled, " + response);
    switchToMainScreen();
    return;
  }

  Log.d(TAG, "Select players UI succeeded.");

  // get the invitee list
  final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
  Log.d(TAG, "Invitee count: " + invitees.size());

  // get the automatch criteria
  Bundle autoMatchCriteria = null;
  int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
  int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
  if (minAutoMatchPlayers > 0 || maxAutoMatchPlayers > 0) {
    autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
        minAutoMatchPlayers, maxAutoMatchPlayers, 0);
    Log.d(TAG, "Automatch criteria: " + autoMatchCriteria);
  }

  // create the room
  Log.d(TAG, "Creating room...");
  switchToScreen(R.id.screen_wait);
  keepScreenOn();
  resetGameVars();

  mRoomConfig = RoomConfig.builder(mRoomUpdateCallback)
      .addPlayersToInvite(invitees)
      .setOnMessageReceivedListener(mOnRealTimeMessageReceivedListener)
      .setRoomStatusUpdateCallback(mRoomStatusUpdateCallback)
      .setAutoMatchCriteria(autoMatchCriteria).build();
  mRealTimeMultiplayerClient.create(mRoomConfig);
  Log.d(TAG, "Room created, waiting for it to be ready...");
}
 
Example 10
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action.equals(ACTION_DISMISS_NOTIFICATION)) {
        String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);
        String tag = intent.getStringExtra(EXTRA_NOTIFICATION_TAG);
        int id = intent.getIntExtra(EXTRA_NOTIFICATION_ID, INVAID_ID);
        cancelNotification(packageName, tag, id);
    } else if (action.equals(ACTION_PREFERENCE_CHANGED)) {
        // Update user preferences.
        String changedKey = intent.getStringExtra(PreferenceKeys.INTENT_ACTION_KEY);
        String newValue = intent.getStringExtra(PreferenceKeys.INTENT_ACTION_NEW_VALUE);

        if (changedKey.equals(PreferenceKeys.PREF_PEEK_TIMEOUT)) {
            mPeekTimeoutMultiplier = Integer.parseInt(newValue);
        } else if (changedKey.equals(PreferenceKeys.PREF_SENSOR_TIMEOUT)) {
            mSensorTimeoutMultiplier = Integer.parseInt(newValue);
        } else if (changedKey.equals(PreferenceKeys.PREF_ALWAYS_SHOW_CONTENT)) {
            mShowContent = Boolean.parseBoolean(newValue);
        } else if (changedKey.equals(PreferenceKeys.PREF_BACKGROUND) ||
                changedKey.equals(PreferenceKeys.PREF_DIM) ||
                changedKey.equals(PreferenceKeys.PREF_RADIUS)) {
            mNotificationPeek.updateBackgroundImageView();
        }
    } else if (action.equals(Intent.ACTION_WALLPAPER_CHANGED)) {
        // Wallpaper has been changed, update Peek.
        mNotificationPeek.updateBackgroundImageView();
    } else if (action.equals(ACTION_QUIET_HOUR_CHANGE)) {
        // Quiet hour has been changed, update AppList settings.
        mAppList.updateQuietHour();
    }
}
 
Example 11
Source Project: product-emm   File: DeviceStateICS.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public float getBatteryLevel() {
	Intent batteryIntent = context.registerReceiver(null,
	                                                new IntentFilter(
                                                            Intent.ACTION_BATTERY_CHANGED));
	int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, DEFAULT_LEVEL);
	int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, DEFAULT_LEVEL);
	return ((float) level / (float) scale) * PRECENTAGE_MULTIPLIER;
}
 
Example 12
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK && data != null) {
        int columnIndex = data.getIntExtra(EXTRA_COLUMN_NUMBER, 0);
        int rowIndex = data.getIntExtra(EXTRA_ROW_NUMBER, 0);
        boolean beforeOrAfter = data.getBooleanExtra(EXTRA_BEFORE_OR_AFTER, true);
        if (requestCode == REQUEST_CODE_EDIT_SONG) {
            String value = data.getStringExtra(EXTRA_VALUE);
            mCsvFileDataSource.updateItem(rowIndex, columnIndex, value);
            mTableAdapter.notifyItemChanged(rowIndex, columnIndex);
        } else if (requestCode == REQUEST_CODE_SETTINGS) {
            applySettings(data);
        } else if (requestCode == REQUEST_CODE_DELETE_ROW) {
            showDeleteDialog(rowIndex, 0);
        } else if (requestCode == REQUEST_CODE_DELETE_ROW_CONFIRMED) {
            applyChanges(DELETE_ROW, rowIndex, false);
        } else if (requestCode == REQUEST_CODE_ADD_ROW) {
            showAddRowDialog(rowIndex);
        } else if (requestCode == REQUEST_CODE_ADD_ROW_CONFIRMED) {
            applyChanges(ADD_ROW, rowIndex, beforeOrAfter);
        } else if (requestCode == REQUEST_CODE_DELETE_COLUMN) {
            showDeleteDialog(0, columnIndex);
        } else if (requestCode == REQUEST_CODE_DELETE_COLUMN_CONFIRMED) {
            applyChanges(DELETE_COLUMN, columnIndex, false);
        } else if (requestCode == REQUEST_CODE_ADD_COLUMN) {
            showAddColumnDialog(columnIndex);
        } else if (requestCode == REQUEST_CODE_ADD_COLUMN_CONFIRMED) {
            applyChanges(ADD_COLUMN, columnIndex, beforeOrAfter);
        }
    }
}
 
Example 13
Source Project: MOAAP   File: MainActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_2_0, this, mOpenCVCallBack);

    if(getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    ivImage1 = (ImageView)findViewById(R.id.ivImage1);
    tvKeyPointsObject1 = (TextView) findViewById(R.id.tvKeyPointsObject1);
    tvKeyPointsObject2 = (TextView) findViewById(R.id.tvKeyPointsObject2);
    tvKeyPointsMatches = (TextView) findViewById(R.id.tvKeyPointsMatches);
    keypointsObject1 = keypointsObject2 = keypointMatches = -1;
    tvTime = (TextView) findViewById(R.id.tvTime);
    Intent intent = getIntent();

    if(intent.hasExtra("ACTION_MODE")){
        ACTION_MODE = intent.getIntExtra("ACTION_MODE", 0);
    }

    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        Log.i("permission", "request READ_EXTERNAL_STORAGE");
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                REQUEST_READ_EXTERNAL_STORAGE);
    }else {
        Log.i("permission", "READ_EXTERNAL_STORAGE already granted");
        read_external_storage_granted = true;
    }
}
 
Example 14
Source Project: mytracks   File: BigTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the battery info of device, and then writes it to a file.
 * 
 * @param context the context of application
 */
public static String getBatteryUsageInfo(Context context) {
  Intent batteryIntent = context.getApplicationContext().registerReceiver(null,
      new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
  int rawlevel = batteryIntent.getIntExtra("level", -1);
  double scale = batteryIntent.getIntExtra("scale", -1);
  return String.format("Device has %s of %s battery left", rawlevel, scale);
}
 
Example 15
private void perhapsShowAlarmFragment(Intent intent) {
    int extraValue = intent.getIntExtra(AlarmDialogFragment.EXTRA_VALUE, 0);

    if (INTENT_ALARM_ACTION.equals(intent.getAction()) && extraValue != 0) {

        AlarmDialogFragment fragment = AlarmDialogFragment.build(
                intent.getBooleanExtra(AlarmDialogFragment.EXTRA_IS_HIGH, false),
                intent.getIntExtra(AlarmDialogFragment.EXTRA_TREND_ORDINAL, 0), extraValue);

        Fragment oldFragment = getFragmentManager().findFragmentByTag("alarm");
        if (oldFragment != null) ((AlarmDialogFragment) oldFragment).dismiss();

        fragment.show(getFragmentManager().beginTransaction(), "alarm");
    }
}
 
Example 16
@Override
public void onCreate(Bundle icicle)
{
    setTheme(AppSettings.loadTheme(this));
    super.onCreate(icicle);
    initLocale();
    setResult(RESULT_CANCELED);
    setContentView(R.layout.layout_activity_themelist);

    Intent intent = getIntent();
    previewID = intent.getIntExtra(WidgetThemeConfigActivity.PARAM_PREVIEWID, previewID);
    disallowSelect = intent.getBooleanExtra(PARAM_NOSELECT, disallowSelect);
    preselectedTheme = intent.getStringExtra(PARAM_SELECTED);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    useWallpaper = prefs.getBoolean(WidgetThemeConfigActivity.PARAM_WALLPAPER, useWallpaper);
    useWallpaper = intent.getBooleanExtra(WidgetThemeConfigActivity.PARAM_WALLPAPER, useWallpaper);

    WidgetThemes.initThemes(this);
    initData(this);
    initViews(this);

    if (preselectedTheme != null && !preselectedTheme.trim().isEmpty())
    {
        int i = adapter.ordinal(preselectedTheme);
        SuntimesTheme.ThemeDescriptor theme = (SuntimesTheme.ThemeDescriptor) adapter.getItem(i);
        triggerActionMode(null, theme);
        gridView.setSelection(i);
    }
}
 
Example 17
Source Project: ToDoList   File: ClockActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStatusBar();
    setContentView(R.layout.activity_clock);
    Intent intent = getIntent();
    clockTitle = intent.getStringExtra("clocktitle");
    workLength = intent.getIntExtra("workLength",ClockApplication.DEFAULT_WORK_LENGTH);
    shortBreak = intent.getIntExtra("shortBreak",ClockApplication.DEFAULT_SHORT_BREAK);
    longBreak = intent.getIntExtra("longBreak",ClockApplication.DEFAULT_LONG_BREAK);
    id = intent.getLongExtra("id",1);

    mApplication = (ClockApplication)getApplication();

    mBtnStart = (Button)findViewById(R.id.btn_start);
    mBtnPause = (Button)findViewById(R.id.btn_pause);
    mBtnResume = (Button)findViewById(R.id.btn_resume);
    mBtnStop = (Button)findViewById(R.id.btn_stop);
    mBtnSkip = (Button)findViewById(R.id.btn_skip);
    mTextCountDown = (TextView)findViewById(R.id.text_count_down);
    mTextTimeTile = (TextView)findViewById(R.id.text_time_title);
    mProgressBar = (ClockProgressBar)findViewById(R.id.tick_progress_bar);
    mRippleWrapper = (RippleWrapper)findViewById(R.id.ripple_wrapper);
    focus_tint = (TextView)findViewById(R.id.focus_hint);
    bt_music = (ImageButton) findViewById(R.id.bt_music);
    clock_bg = (ImageView) findViewById(R.id.clock_bg);
    if(isSoundOn()){
        bt_music.setEnabled(true);
        bt_music.setImageDrawable(getResources().getDrawable(R.drawable.ic_music));
    } else {
        bt_music.setEnabled(false);
        bt_music.setImageDrawable(getResources().getDrawable(R.drawable.ic_music_off));
    }
    SPUtils.put(this,"music_id",R.raw.river);
    Toasty.normal(this, "双击界面打开或关闭白噪音", Toast.LENGTH_SHORT).show();
    initActions();
    initBackgroundImage();
}
 
Example 18
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // retrieve the error code, if available
    int errorCode = -1;
    if (data != null) {
        errorCode = data.getIntExtra(WalletConstants.EXTRA_ERROR_CODE, -1);
    }
    switch (requestCode) {
        case REQUEST_CODE_MASKED_WALLET:
            switch (resultCode) {
                case Activity.RESULT_OK:
                    if (data != null) {
                        MaskedWallet maskedWallet =
                                data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET);
                        launchConfirmationPage(maskedWallet);
                    }
                    break;
                case WalletConstants.RESULT_ERROR:
                    handleError(errorCode);
                    break;
                case Activity.RESULT_CANCELED:
                    break;
                default:
                    handleError(errorCode);
                    break;
            }
            break;
        default:
            super.onActivityResult(requestCode, resultCode, data);
            break;
    }
}
 
Example 19
public static int getPreviousProfileState(Intent intent) {
    return intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1);
}
 
Example 20
Source Project: Pi-Locker   File: Lock.java    License: GNU General Public License v2.0 3 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

	int level = intent.getIntExtra("level", 0);
	int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
	boolean batteryCharge = status == BatteryManager.BATTERY_STATUS_CHARGING;

	int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
	boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
	boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;

	if ((acCharge) || (usbCharge) || (batteryCharge)) {

		battery.setText(level + "% ");
		battery.setTextColor(Color.GREEN);

	} else if (level < 20) {

		battery.setTextColor(Color.RED);
		battery.setText(level + "% ");
	}

	else {

		battery.setText(level + "% ");
		battery.setTextColor(Integer.parseInt(color));

	}

}