Arama butonu
Bu konudaki kullanıcılar: 1 misafir
8
Cevap
171
Tıklama
0
Öne Çıkarma
Android anlayamadığım kod
D
8 yıl
Yarbay
Konu Sahibi


int count;
Button btn;
SharedPreferences preferences,ayarlar;
RelativeLayout arkaplan;
Boolean sesDurumu,titresimDurumu;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


arkaplan = (RelativeLayout) findViewById(R.id.rl);
btn = (Button) findViewById(R.id.button);
preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
ayarlar = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
ayarlariYukle();
final MediaPlayer ses=MediaPlayer.create(getApplicationContext(),R.raw.sessss);

count=preferences.getInt("count_anahtarı",0);
btn.setText(""+count);
final Vibrator titresim= (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(sesDurumu)
{
ses.start();
}
if(titresimDurumu)
{
titresim.vibrate(250);
}
count++;
btn.setText(""+count);
}
});

}

private void ayarlariYukle() {
String post = ayarlar.getString("arkaplan","3");
switch (Integer.valueOf(post))
{
case 0:
arkaplan.setBackgroundColor(Color.RED);
break;
case 1:
arkaplan.setBackgroundColor(Color.GREEN);
break;
case 2:
arkaplan.setBackgroundColor(Color.BLUE);
break;
case 3:
arkaplan.setBackgroundColor(Color.DKGRAY);
break;
case 4:
arkaplan.setBackgroundColor(Color.LTGRAY);
break;

}

sesDurumu = ayarlar.getBoolean("ses",false);
titresimDurumu = ayarlar.getBoolean("titresim",false);
ayarlar.registerOnSharedPreferenceChangeListener(MainActivity.this);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main,menu);
return super.onCreateOptionsMenu(menu);
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()){
case R.id.sifirla:
count=0;
btn.setText(""+count);
break;
case R.id.ayarlar:
Intent intent = new Intent(getApplicationContext(),Ayarlar.class);
startActivity(intent);
break;
}

return super.onOptionsItemSelected(item);
}

@Override
protected void onPause() {
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("count_anahtarı",count);
editor.commit();
super.onPause();
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
ayarlariYukle();
}
}




kodu tamamen attım arkadaşlar burdaki SharedPrefences türü ve ayarlar değişkenini anlamadım.ayarların benim görebildiğim ayarlar.class ile bağlantısı yok veya ayarları barındıran xml dosyalarıyla fakat program düzgün çalışıyor kaçırdığım yer neresi?