@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals("USE_GPS")) { if (mSettings.isGpsTrackingEnabled()) { stopScheduledLocationUpdates(); startScheduledLocationUpdates(); } else { stopScheduledLocationUpdates(); } return; } if (key.equals("GPS_TIMER") || key.equals("GPS_ONLY_NEW")) { stopScheduledLocationUpdates(); if (mSettings.isGpsTrackingEnabled()) { startScheduledLocationUpdates(); } return; } if (key.equals("GPS_HIDDEN")) { mIsGpsHidden = mSettings.isGpsHidden(); if (mIsGpsHidden) { if (ScreenStateReceiver.getScreenState() != ScreenStateReceiver.SCREEN_STATE_OFF) { stopGpsListeners(); } } else { startGpsListeners(); } return; } }
private void setupButtons() { CheckBox cb = (CheckBox) findViewById(R.id.usefilterCB); cb.setChecked(settings.isFilterEnabled()); cb.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { settings.useFilter(isChecked); } }); RadioGroup rg = (RadioGroup) findViewById(R.id.filterType); String type = settings.filterType(); rg.clearCheck(); if (type.equals("0")) { ((RadioButton) findViewById(R.id.type0)).setChecked(true); } else { ((RadioButton) findViewById(R.id.type1)).setChecked(true); } rg.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.type0: settings.filterType("0"); break; case R.id.type1: settings.filterType("1"); break; default: break; } } }); Button add = (Button) findViewById(R.id.addButton); add.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { String num = ((EditText) findViewById(R.id.editNum)).getText().toString(); // if (num.length() != 10){ // Toast.makeText(FilterActivity.this, "Необходимо ввести // ДЕСЯТ�ЗНАЧНЫЙ номер телефона без кода страны. // Например: 9031234567", Toast.LENGTH_LONG).show(); // return; // } settings.filterAdd(num); renderList(); } }); }
private void renderList() { String fList = settings.filterList(); String[] arr = {}; if (fList.length() > 0) { arr = fList.split(","); } ArrayList<String> list = new ArrayList<String>(); for (Integer i = 0; i < arr.length; i++) { list.add(arr[i]); } ListView lv = (ListView) findViewById(R.id.number_list); final NumberListAdapter adapter = new NumberListAdapter(this, list); lv.setAdapter(adapter); lv.setOnItemLongClickListener( new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { String num = (String) adapter.getItem(position); settings.filterDel(num); renderList(); return true; } }); }
public LocationModule(Context context) { mContext = context; mSettings = new SettingsManager(context); mSingleListeners = new ArrayList<SingleLocationListener>(); mIsGpsHidden = mSettings.isGpsHidden(); mScreenStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int state = intent.getIntExtra( ScreenStateReceiver.SCREEN_STATE_EXTRA, ScreenStateReceiver.SCREEN_STATE_UNKNOWN); switch (state) { case ScreenStateReceiver.SCREEN_STATE_OFF: startGpsListeners(); break; case ScreenStateReceiver.SCREEN_STATE_ON: if (mIsGpsHidden) { stopGpsListeners(); } break; default: break; } } }; sHandler = new MyHandler(this); PreferenceManager.getDefaultSharedPreferences(context) .registerOnSharedPreferenceChangeListener(this); }
public synchronized void start() { LocalBroadcastManager.getInstance(mContext) .registerReceiver(mScreenStateReceiver, new IntentFilter(ScreenStateReceiver.SCREEN_EVENT)); if (mSettings.isGpsTrackingEnabled()) { startScheduledLocationUpdates(); } }