If you think the Android project EBrowser listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Zirco Browser for Android//fromwww.java2s.com
*
* Copyright (C) 2010 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/package org.zirco.ui.activities.preferences;
import com.mrpej.ebrowser.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
/**
* Base class for a dialog activity for a preference which can have several predefined values, and a customizable one.
*/publicabstractclass BaseSpinnerCustomPreferenceActivity extends Activity {
protected Spinner mSpinner;
protected EditText mCustomEditText;
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window w = getWindow();
w.requestFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.base_spinner_custom_preference_activity);
w.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.ic_dialog_map);
mCustomEditText = (EditText) findViewById(R.id.BaseSpinnerCustomPreferenceEditText);
mSpinner = (Spinner) findViewById(R.id.BaseSpinnerCustomPreferenceSpinner);
mSpinner.setPromptId(getSpinnerPromptId());
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, getSpinnerValuesArrayId(), android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinner.setAdapter(adapter);
setSpinnerValueFromPreferences();
mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
publicvoid onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
onSpinnerItemSelected(position);
}
@Override
publicvoid onNothingSelected(AdapterView<?> arg0) { }
});
Button okBtn = (Button) findViewById(R.id.BaseSpinnerCustomPreferenceOk);
okBtn.setOnClickListener(new OnClickListener() {
@Override
publicvoid onClick(View v) {
onOk();
finish();
}
});
Button cancelBtn = (Button) findViewById(R.id.BaseSpinnerCustomPreferenceCancel);
cancelBtn.setOnClickListener(new OnClickListener() {
@Override
publicvoid onClick(View v) {
finish();
}
});
}
/**
* Get the resource id for the prompt of the spinner.
* @return The resource id.
*/protectedabstractint getSpinnerPromptId();
/**
* Get the resource id for the array values of the spinner.
* @return The array id.
*/protectedabstractint getSpinnerValuesArrayId();
/**
* Initialize the spinner with the current value in preferences.
*/protectedabstractvoid setSpinnerValueFromPreferences();
/**
* Behavior when the spinner selected item change.
* @param position The new selected index.
*/protectedabstractvoid onSpinnerItemSelected(int position);
/**
* Behavior when the user press the Ok button.
*/protectedabstractvoid onOk();
}