@Override public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { inflater.inflate(R.menu.sending_addresses_fragment_options, menu); final PackageManager pm = activity.getPackageManager(); menu.findItem(R.id.sending_addresses_options_scan) .setVisible( pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)); super.onCreateOptionsMenu(menu, inflater); }
private static boolean saveDownloadDataWifiOnlyPref(Context context) { PackageManager pm = context.getPackageManager(); boolean supportsTelephony = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); boolean supportsWifi = pm.hasSystemFeature(PackageManager.FEATURE_WIFI); if (!supportsWifi || !supportsTelephony) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); editor.putBoolean(KEY_GPS_DOWNLOAD_DATA_WIFI_ONLY, supportsWifi); editor.apply(); return true; } return false; }
/** * Checks camera availability recursively based on API level. * * <p>TODO: change "android.hardware.camera.front" and "android.hardware.camera.any" to {@link * PackageManager#FEATURE_CAMERA_FRONT} and {@link PackageManager#FEATURE_CAMERA_ANY}, * respectively, once they become accessible or minSdk version is incremented. * * @param context The context. * @return Whether camera is available. */ public boolean hasCamera(Context context) { final PackageManager pm = context.getPackageManager(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) || pm.hasSystemFeature("android.hardware.camera.front"); } return pm.hasSystemFeature("android.hardware.camera.any"); }
/** * Check that if the PackageManager declares a sensor feature that the device has at least one * sensor that matches that feature. Also check that if a PackageManager does not declare a sensor * that the device also does not have such a sensor. * * @param featuresLeft to check in order to make sure the test covers all sensor features * @param expectedFeature that the PackageManager may report * @param expectedSensorType that that {@link SensorManager#getSensorList(int)} may have */ private void assertFeatureForSensor( Set<String> featuresLeft, String expectedFeature, int expectedSensorType) { assertTrue( "Features left " + featuresLeft + " to check did not include " + expectedFeature, featuresLeft.remove(expectedFeature)); boolean hasSensorFeature = mPackageManager.hasSystemFeature(expectedFeature); List<Sensor> sensors = mSensorManager.getSensorList(expectedSensorType); List<String> sensorNames = new ArrayList<String>(sensors.size()); for (Sensor sensor : sensors) { sensorNames.add(sensor.getName()); } boolean hasSensorType = !sensors.isEmpty(); String message = "PackageManager#hasSystemFeature(" + expectedFeature + ") returns " + hasSensorFeature + " but SensorManager#getSensorList(" + expectedSensorType + ") shows sensors " + sensorNames; assertEquals(message, hasSensorFeature, hasSensorType); }
private void assertNotAvailable(String feature) { assertFalse( "PackageManager#hasSystemFeature should NOT return true for " + feature, mPackageManager.hasSystemFeature(feature)); assertFalse( "PackageManager#getSystemAvailableFeatures should NOT have " + feature, mAvailableFeatures.contains(feature)); }
public static boolean isFlashSupported(Context context) { PackageManager packageManager = context.getPackageManager(); // if device support camera flash? if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) { return true; } return false; }
/** * 判断设备是否有摄像头 * * @param context * @return */ public static boolean hasCamera(Context context) { PackageManager packageManager = context.getPackageManager(); if (!packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) { return false; } return true; }
protected void initWebViewSettings(WebView w) { w.setScrollbarFadingEnabled(true); w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); w.setMapTrackballToArrowKeys(false); // use trackball directly // Enable the built-in zoom w.getSettings().setBuiltInZoomControls(true); /// M: Add to disable overscroll mode w.setOverScrollMode(View.OVER_SCROLL_NEVER); final PackageManager pm = mContext.getPackageManager(); boolean supportsMultiTouch = pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH) || pm.hasSystemFeature(PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT); w.getSettings().setDisplayZoomControls(!supportsMultiTouch); // Add this WebView to the settings observer list and update the // settings final BrowserSettings s = BrowserSettings.getInstance(); s.startManagingSettings(w.getSettings()); }
private void init() { Context context = this; PackageManager pm = context.getPackageManager(); // if device support camera? if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) | !pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) { Log.e("err", "Device has no camera!"); Toast.makeText(this, R.string.no_flash, Toast.LENGTH_LONG); btnSwitch.setEnabled(false); return; } camera = Camera.open(); isConnected = true; p = camera.getParameters(); btnSwitch.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View arg0) { if (flashState) { // "info", "torch is turn off!" p.setFlashMode(Parameters.FLASH_MODE_OFF); camera.setParameters(p); camera.stopPreview(); flashState = false; btnSwitch.setImageDrawable(getResources().getDrawable(R.drawable.off)); } else { // "info", "torch is turn on!" p.setFlashMode(Parameters.FLASH_MODE_TORCH); camera.setParameters(p); camera.startPreview(); flashState = true; btnSwitch.setImageDrawable(getResources().getDrawable(R.drawable.on)); } } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); // Set up the drawer. mNavigationDrawerFragment.setUp( R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); FragmentManager fragmentManager = getFragmentManager(); // GlobalFeedFragment feedFragment = new GlobalFeedFragment(); // fragmentManager.beginTransaction().replace(R.id.container, feedFragment).commit(); mStepValue = 0; mPaceValue = 0; startService(new Intent(this, Time.class)); Log.i(TAG, "Started service"); try { if (!mIsRunning) { p1_button.setText("Start ►"); // p1_button.setBackgroundResource(R.drawable.resume); } else if (mIsRunning) { p1_button.setText("Stop ◼"); // p1_button.setBackgroundResource(R.drawable.pause); } } catch (NullPointerException e) { } mPedometerUtils = PedometerUtils.getInstance(); RebootSteps = (TextView) findViewById(R.id.time); RS = (TextView) findViewById(R.id.textView8); PackageManager m = getPackageManager(); if (!m.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER)) { RS.setVisibility(View.INVISIBLE); RebootSteps.setVisibility(View.INVISIBLE); } mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mStepCounterSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); mStepDetectorSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR); }
@Override protected void onCreate(Bundle bundle) { UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE); if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) { // tv = true; } PackageManager pm = getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) { touchscreen = false; } setUncaughtExceptionHandler(); applyTheme(); applyFullscreen(); super.onCreate(bundle); startService(new Intent(this, DownloadService.class)); setVolumeControlStream(AudioManager.STREAM_MUSIC); if (getIntent().hasExtra(Constants.FRAGMENT_POSITION)) { lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0); } if (preferencesListener == null) { preferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // When changing drawer settings change visibility switch (key) { case Constants.PREFERENCES_KEY_PODCASTS_ENABLED: setDrawerItemVisible(R.id.drawer_podcasts, false); break; case Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED: setDrawerItemVisible(R.id.drawer_bookmarks, false); break; case Constants.PREFERENCES_KEY_SHARED_ENABLED: setDrawerItemVisible(R.id.drawer_shares, false); break; case Constants.PREFERENCES_KEY_CHAT_ENABLED: setDrawerItemVisible(R.id.drawer_chat, false); break; case Constants.PREFERENCES_KEY_ADMIN_ENABLED: setDrawerItemVisible(R.id.drawer_admin, false); break; } } }; Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener); } }
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @SuppressWarnings("deprecation") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Ensure we have a camera! PackageManager pm = this.getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) { finish(); return; } addPreferencesFromResource(R.xml.preferences); cameraIndexPreference = (ListPreference) findPreference("pref_cameraIndex"); cameraResolutionPreference = (ListPreference) findPreference("pref_cameraResolution"); // One time only, we need to build a list of cameras. If more than // one camera, enable the cameraIndexPreference. Otherwise, disable it. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { cameraCount = Camera.getNumberOfCameras(); Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); int cameraCountFront = 0; int cameraCountRear = 0; CharSequence[] entries = new CharSequence[cameraCount]; CharSequence[] entryValues = new CharSequence[cameraCount]; for (int camIndex = 0; camIndex < cameraCount; camIndex++) { Camera.getCameraInfo(camIndex, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { cameraCountFront++; entries[camIndex] = "Front camera"; if (cameraCountFront > 1) entries[camIndex] = entries[camIndex] + " " + cameraCountFront; } else { cameraCountRear++; entries[camIndex] = "Rear camera"; if (cameraCountRear > 1) entries[camIndex] = entries[camIndex] + " " + cameraCountRear; } entryValues[camIndex] = Integer.toString(camIndex); } cameraIndexPreference.setEnabled(true); cameraIndexPreference.setEntries(entries); cameraIndexPreference.setEntryValues(entryValues); } else { cameraCount = 1; cameraIndexPreference.setEnabled(false); } buildResolutionListForCameraIndex(); }
public void getCamera() { PackageManager pm = getPackageManager(); if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) { try { Intent i = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE); i.putExtra("android.intent.extra.durationLimit", 8); // i.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); startActivityForResult(i, VIDEO_RESULT); } catch (Exception e) { } } else { Toast.makeText(getBaseContext(), "Camera is not available", Toast.LENGTH_LONG).show(); } }
public UsbService(Context context) { mContext = context; mDeviceManager = new UsbDeviceSettingsManager(context); PackageManager pm = mContext.getPackageManager(); mHasUsbAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY); synchronized (mLock) { init(); // set initial status // Watch for USB configuration changes if (mConfiguration >= 0) { if (mLegacy) { mUEventObserver.startObserving(USB_LEGACY_MATCH); } else { mUEventObserver.startObserving(USB_CONNECTED_MATCH); mUEventObserver.startObserving(USB_CONFIGURATION_MATCH); mUEventObserver.startObserving(USB_FUNCTIONS_MATCH); } } } }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private boolean initNearby() { PackageManager pm = getPackageManager(); if (pm != null && pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); BluetoothAdapter adapter = manager.getAdapter(); if (adapter != null) { MetadataResolver.initialize(this); mDeviceManager = new NearbyDeviceManager(this, adapter); mDeviceManager .getAdapter() .registerDataSetObserver( new DataSetObserver() { @Override public void onChanged() { updateNearbyButton(); } }); return true; } } return false; }
public UsbDeviceManager(Context context) { mContext = context; mContentResolver = context.getContentResolver(); PackageManager pm = mContext.getPackageManager(); mHasUsbAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY); initRndisAddress(); readOemUsbOverrideConfig(); // create a thread for our Handler HandlerThread thread = new HandlerThread("UsbDeviceManager", Process.THREAD_PRIORITY_BACKGROUND); thread.start(); mHandler = new UsbHandler(thread.getLooper()); if (nativeIsStartRequested()) { if (DEBUG) Slog.d(TAG, "accessory attached at boot"); startAccessoryMode(); } if ("1".equals(SystemProperties.get("ro.adb.secure"))) { mDebuggingManager = new UsbDebuggingManager(context); } }
public UsbDeviceManager(Context context, UsbAlsaManager alsaManager) { mContext = context; mUsbAlsaManager = alsaManager; mContentResolver = context.getContentResolver(); PackageManager pm = mContext.getPackageManager(); mHasUsbAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY); initRndisAddress(); readOemUsbOverrideConfig(); mHandler = new UsbHandler(FgThread.get().getLooper()); if (nativeIsStartRequested()) { if (DEBUG) Slog.d(TAG, "accessory attached at boot"); startAccessoryMode(); } boolean secureAdbEnabled = SystemProperties.getBoolean("ro.adb.secure", false); boolean dataEncrypted = "1".equals(SystemProperties.get("vold.decrypt")); if (secureAdbEnabled && !dataEncrypted) { mDebuggingManager = new UsbDebuggingManager(context); } mContext.registerReceiver(mHostReceiver, new IntentFilter(UsbManager.ACTION_USB_PORT_CHANGED)); }
/** @return Whether biometric weak lock is installed and that the front facing camera exists */ public boolean isBiometricWeakInstalled() { // Check that the system flag was set if (!OPTION_ENABLE_FACELOCK.equals(getString(LOCKSCREEN_OPTIONS))) { return false; } // Check that it's installed PackageManager pm = mContext.getPackageManager(); try { pm.getPackageInfo("com.android.facelock", PackageManager.GET_ACTIVITIES); } catch (PackageManager.NameNotFoundException e) { return false; } // Check that the camera is enabled if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) { return false; } if (getDevicePolicyManager().getCameraDisabled(null)) { return false; } return true; }
private boolean isPhoneVisible() { PackageManager pm = mContext.getPackageManager(); return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) && pm.resolveActivity(PHONE_INTENT, 0) != null; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.main); button = (Button) findViewById(R.id.buttonFlashlight); buttonSos = (Button) findViewById(R.id.buttonSos); buttonMenu = (ImageButton) findViewById(R.id.imageButton1); PackageManager pm = getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) { flashNotSupportedAlert(); return; } camera = Camera.open(); final Parameters p = camera.getParameters(); button.setOnClickListener( new OnClickListener() { public void onClick(View arg0) { if (isSosOn) { isSosOn = false; sosOff(); flashOn(); } else { if (isFlashOn) { flashOff(); } else { flashOn(); flashTimerHandler.postDelayed(updateFlashTimerThread, 0); } } } }); buttonSos.setOnClickListener( new OnClickListener() { public void onClick(View arg0) { if (isSosOn) { isSosOn = false; sosOff(); flashOff(); } else { isSosOn = true; sosOn(); } } }); buttonMenu.setOnClickListener( new OnClickListener() { public void onClick(View arg0) { openOptionsMenu(); } }); sosOff(); flashOn(); flashTimerHandler.postDelayed(updateFlashTimerThread, 0); initStatus(); }
public boolean isCameraAvailable() { PackageManager pm = getPackageManager(); return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA); }
public static boolean deviceSupportsTelephony(Context ctx) { PackageManager pm = ctx.getPackageManager(); return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); }
public boolean isFlashSupported() { PackageManager pm = getPackageManager(); return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); }
@Override @TargetApi(11) public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_crime, parent, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); } mTitleField = (EditText) v.findViewById(R.id.crime_title); mTitleField.setText(mCrime.getTitle()); mTitleField.addTextChangedListener( new TextWatcher() { public void onTextChanged(CharSequence c, int start, int before, int count) { mCrime.setTitle(c.toString()); } public void beforeTextChanged(CharSequence c, int start, int count, int after) { // this space intentionally left blank } public void afterTextChanged(Editable c) { // this one too } }); mDateButton = (Button) v.findViewById(R.id.crime_date); updateDate(); mDateButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { FragmentManager fm = getActivity().getSupportFragmentManager(); DatePickerFragment dialog = DatePickerFragment.newInstance(mCrime.getDate()); dialog.setTargetFragment(CrimeFragment.this, REQUEST_DATE); dialog.show(fm, DIALOG_DATE); } }); mSolvedCheckBox = (CheckBox) v.findViewById(R.id.crime_solved); mSolvedCheckBox.setChecked(mCrime.isSolved()); mSolvedCheckBox.setOnCheckedChangeListener( new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // set the crime's solved property mCrime.setSolved(isChecked); } }); mPhotoButton = (ImageButton) v.findViewById(R.id.crime_imageButton); mPhotoButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { // launch the camera activity Intent i = new Intent(getActivity(), CrimeCameraActivity.class); startActivity(i); } }); // if camera is not available, disable camera functionality PackageManager pm = getActivity().getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) && !pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) { mPhotoButton.setEnabled(false); } return v; }
public static boolean a(PackageManager packagemanager) { return packagemanager.hasSystemFeature("com.google.android.tv"); }
public void testScreenFeatures() { assertTrue( mPackageManager.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE) || mPackageManager.hasSystemFeature(PackageManager.FEATURE_SCREEN_PORTRAIT)); }
/** * Determines whether BLE is supported or not. * * @param callbackContext The callback id used when calling back into JavaScript */ private void isBleSupported(final CallbackContext callbackContext) { if (packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) callbackContext.success(); else callbackContext.error("BLE is not supported."); }
@TargetApi(11) @Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstance) { // Get view for fragment View v = inflater.inflate(R.layout.fragment_crime, parent, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (NavUtils.getParentActivityName(getActivity()) != null) { getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); } } // Crime Title mTitleField = (EditText) v.findViewById(R.id.crime_title); mTitleField.setText(mCrime.getTitle()); mTitleField.addTextChangedListener( new TextWatcher() { public void onTextChanged(CharSequence c, int start, int before, int count) { mCrime.setTitle(c.toString()); mCallbacks.onCrimeUpdated(mCrime); } public void beforeTextChanged(CharSequence c, int start, int count, int after) { // Do something? } public void afterTextChanged(Editable c) { // Do something? } }); Log.d("KIO", "Crime title is: " + mTitleField); // Date Button mDateButton = (Button) v.findViewById(R.id.crime_date); updateDate(); mDateButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fm = getActivity().getSupportFragmentManager(); DatePickerFragment dialog = DatePickerFragment.newInstance(mCrime.getDate()); dialog.setTargetFragment(CrimeFragment.this, REQUEST_DATE); dialog.show(fm, DIALOG_DATE); } }); Log.d("KIO", "Date is: " + mDateButton); // Time Button mTimeButton = (Button) v.findViewById(R.id.crime_time); Log.d("KIO", "Time is: " + mTimeButton); updateTime(); mTimeButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fm = getActivity().getSupportFragmentManager(); TimePickerFragment dialog = TimePickerFragment.newInstance(mCrime.getDate()); dialog.setTargetFragment(CrimeFragment.this, REQUEST_TIME); dialog.show(fm, DIALOG_TIME); } }); Log.d("KIO", "Time is: " + mTimeButton); // "Solved" Check box mSolvedCheckBox = (CheckBox) v.findViewById(R.id.crime_solved); mSolvedCheckBox.setChecked(mCrime.isSolved()); mSolvedCheckBox.setOnCheckedChangeListener( new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // Set the crime's solved property mCrime.setSolved(isChecked); mCallbacks.onCrimeUpdated(mCrime); } }); // Photo Button mPhotoButton = (ImageButton) v.findViewById(R.id.crime_imageButton); mPhotoButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getActivity(), CrimeCameraActivity.class); startActivityForResult(i, REQUEST_PHOTO); } }); // If a camera is not available, disable the camera functionality PackageManager pm = getActivity().getPackageManager(); boolean hasACamera = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Camera.getNumberOfCameras() > 0); if (!hasACamera) { mPhotoButton.setEnabled(false); } // Photographic Evidence mPhotoView = (ImageView) v.findViewById(R.id.crime_imageView); mPhotoView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Photo p = mCrime.getPhoto(); if (p == null) { return; } FragmentManager fm = getActivity().getSupportFragmentManager(); String path = getActivity().getFileStreamPath(p.getFilename()).getAbsolutePath(); ImageFragment.newInstance(path).show(fm, DIALOG_IMAGE); } }); // Crime Report Button reportButton = (Button) v.findViewById(R.id.crime_reportButton); reportButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_TEXT, getCrimeReport()); i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.crime_report_subject)); // Always show the chooser, even if the user has set a default app i = Intent.createChooser(i, getString(R.string.send_report)); startActivity(i); } }); // Suspect mSuspectButton = (Button) v.findViewById(R.id.crime_suspectButton); mSuspectButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(i, REQUEST_CONTACT); } }); if (mCrime.getSuspect() != null) { mSuspectButton.setText(mCrime.getSuspect()); } return v; }
/** * function to check if device has GPS hardware * * @return Boolean: true present, false otherwise */ public static boolean isGPSHardwarePresent(Context context) { PackageManager pm = context.getPackageManager(); return pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String version = "?"; try { PackageInfo manager = getPackageManager().getPackageInfo(getPackageName(), 0); version = manager.versionName; } catch (NameNotFoundException e) { Log.i(TAG, "NameNotFoundException e:" + e); e.printStackTrace(); } StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); String theDate = sdf.format(new Date()); Log.i(TAG, "theDate:" + theDate); Log.i(TAG, "version " + version); System.out.println( ">>>>>> >>>>>>>>>> Starting MainActivity."); // // experimenting // ActyTest.proto1(1, getApplicationContext()); // // END experimenting // Globals g = Globals.getInstance(); PackageManager pm = getApplicationContext().getPackageManager(); String haves = ""; boolean hasGps = pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS); if (hasGps) { haves += "This device has a gps."; } else { haves += "This device does not have a gps."; } ; if (isNetworkAvailable()) { haves += "The network is available."; } else { haves += "The network is not available."; } ; makeToast(haves); Utilities.readPlansTasks(getApplicationContext()); Utilities.createByTaskArray(); setContentView(R.layout.activity_main); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); // gets the activity's default ActionBar ActionBar actionBar = getActionBar(); actionBar.show(); // set the app icon as an action to go home // we are home so we don't need it actionBar.setDisplayHomeAsUpEnabled(true); String t = getTitle().toString(); setTitle(t + " version " + version); Button startPlan = (Button) findViewById(R.id.btnPlan); startPlan.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { startPlan(); } }); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); String dwco = sharedPrefs.getString("dwco", ""); Globals.dwco = dwco; System.out.println(TAG + " setting Globals.dwco = " + dwco); String dwcoRequests = sharedPrefs.getString("dwcoRequests", ""); Globals.dwcoRequests = dwcoRequests; System.out.println(TAG + " setting Globals.dwco = " + dwcoRequests); String dwcoReplies = sharedPrefs.getString("dwcoReplies", ""); Globals.dwcoReplies = dwcoReplies; System.out.println(TAG + " setting Globals.dwcoReplies = " + dwcoReplies); Log.i(TAG, "Exiting MainActivity."); System.out.println(TAG + " -- Exiting MainActivity."); }