mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
works predefined image selector
This commit is contained in:
parent
a1b8286a02
commit
15100ec9a2
7 changed files with 113 additions and 27 deletions
|
@ -4,6 +4,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="10dip"
|
||||||
>
|
>
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/background_chooser_item_title"
|
android:id="@+id/background_chooser_item_title"
|
||||||
|
|
33
res/layout/background_predefined_item.xml
Normal file
33
res/layout/background_predefined_item.xml
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="18dip"
|
||||||
|
>
|
||||||
|
<yuku.ambilwarna.widget.AmbilWarnaPrefWidgetView
|
||||||
|
android:id="@+id/background_predefined_item_preview"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center_vertical|left"
|
||||||
|
android:focusable="false"
|
||||||
|
android:clickable="false"
|
||||||
|
/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/background_predefined_item_title"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:paddingRight="8dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
|
/>
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
|
@ -60,6 +60,8 @@ import org.geometerplus.android.util.DeviceType;
|
||||||
public class PreferenceActivity extends ZLPreferenceActivity {
|
public class PreferenceActivity extends ZLPreferenceActivity {
|
||||||
private final ActivityNetworkContext myNetworkContext = new ActivityNetworkContext(this);
|
private final ActivityNetworkContext myNetworkContext = new ActivityNetworkContext(this);
|
||||||
private final FileChooserCollection myChooserCollection = new FileChooserCollection(this, 2000);
|
private final FileChooserCollection myChooserCollection = new FileChooserCollection(this, 2000);
|
||||||
|
private static final int BACKGROUND_REQUEST_CODE = 3000;
|
||||||
|
private BackgroundPreference myBackgroundPreference;
|
||||||
|
|
||||||
public PreferenceActivity() {
|
public PreferenceActivity() {
|
||||||
super("Preferences");
|
super("Preferences");
|
||||||
|
@ -77,9 +79,18 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode != RESULT_OK) {
|
||||||
myChooserCollection.update(requestCode, data);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (BACKGROUND_REQUEST_CODE == requestCode) {
|
||||||
|
if (myBackgroundPreference != null) {
|
||||||
|
myBackgroundPreference.update(data);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
myChooserCollection.update(requestCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -448,9 +459,13 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
||||||
|
|
||||||
final Screen colorsScreen = createPreferenceScreen("colors");
|
final Screen colorsScreen = createPreferenceScreen("colors");
|
||||||
|
|
||||||
colorsScreen.addPreference(new BackgroundPreference(
|
myBackgroundPreference = new BackgroundPreference(
|
||||||
this, profile, colorsScreen.Resource.getResource("background")
|
this,
|
||||||
));
|
profile,
|
||||||
|
colorsScreen.Resource.getResource("background"),
|
||||||
|
BACKGROUND_REQUEST_CODE
|
||||||
|
);
|
||||||
|
colorsScreen.addPreference(myBackgroundPreference);
|
||||||
final WallpaperPreference wallpaperPreference = new WallpaperPreference(
|
final WallpaperPreference wallpaperPreference = new WallpaperPreference(
|
||||||
this, profile, colorsScreen.Resource.getResource("background")
|
this, profile, colorsScreen.Resource.getResource("background")
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -36,15 +36,19 @@ import org.geometerplus.zlibrary.ui.android.util.ZLAndroidColorUtil;
|
||||||
import org.geometerplus.fbreader.fbreader.options.ColorProfile;
|
import org.geometerplus.fbreader.fbreader.options.ColorProfile;
|
||||||
|
|
||||||
public class BackgroundPreference extends Preference {
|
public class BackgroundPreference extends Preference {
|
||||||
|
static final String VALUE_KEY = "fbreader.background.value";
|
||||||
|
|
||||||
private final ZLResource myResource;
|
private final ZLResource myResource;
|
||||||
private final ColorProfile myProfile;
|
private final ColorProfile myProfile;
|
||||||
|
private final int myRequestCode;
|
||||||
|
|
||||||
public BackgroundPreference(Context context, ColorProfile profile, ZLResource resource) {
|
public BackgroundPreference(Context context, ColorProfile profile, ZLResource resource, int requestCode) {
|
||||||
super(context);
|
super(context);
|
||||||
setWidgetLayoutResource(R.layout.background_preference);
|
setWidgetLayoutResource(R.layout.background_preference);
|
||||||
|
|
||||||
myResource = resource;
|
myResource = resource;
|
||||||
myProfile = profile;
|
myProfile = profile;
|
||||||
|
myRequestCode = requestCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -87,6 +91,14 @@ public class BackgroundPreference extends Preference {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onClick() {
|
protected void onClick() {
|
||||||
((Activity)getContext()).startActivity(new Intent(getContext(), Chooser.class));
|
((Activity)getContext()).startActivityForResult(new Intent(getContext(), Chooser.class), myRequestCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Intent data) {
|
||||||
|
final String value = data.getStringExtra(VALUE_KEY);
|
||||||
|
if (value != null) {
|
||||||
|
myProfile.WallpaperOption.setValue(value);
|
||||||
|
}
|
||||||
|
notifyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,9 +49,10 @@ public class Chooser extends ListActivity implements AdapterView.OnItemClickList
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public final void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
System.err.println("CLICKED:" + position);
|
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case 0:
|
case 0:
|
||||||
|
setResult(RESULT_OK, new Intent().putExtra(BackgroundPreference.VALUE_KEY, ""));
|
||||||
|
finish();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
startActivityForResult(new Intent(this, PredefinedImages.class), 1);
|
startActivityForResult(new Intent(this, PredefinedImages.class), 1);
|
||||||
|
@ -61,4 +62,12 @@ public class Chooser extends ListActivity implements AdapterView.OnItemClickList
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (resultCode == RESULT_OK) {
|
||||||
|
setResult(RESULT_OK, data);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,11 @@
|
||||||
package org.geometerplus.android.fbreader.preferences.background;
|
package org.geometerplus.android.fbreader.preferences.background;
|
||||||
|
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
@ -37,26 +39,40 @@ public class PredefinedImages extends ListActivity implements AdapterView.OnItem
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
setTitle(myResource.getValue());
|
setTitle(myResource.getValue());
|
||||||
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
|
final ArrayAdapter<ZLFile> adapter = new ArrayAdapter<ZLFile>(
|
||||||
this, R.layout.background_chooser_item, R.id.background_chooser_item_title
|
this, R.layout.background_predefined_item, R.id.background_predefined_item_title
|
||||||
|
) {
|
||||||
|
public View getView(int position, View convertView, final ViewGroup parent) {
|
||||||
|
final View view = super.getView(position, convertView, parent);
|
||||||
|
|
||||||
|
final TextView titleView =
|
||||||
|
(TextView)view.findViewById(R.id.background_predefined_item_title);
|
||||||
|
final String name = getItem(position).getShortName();
|
||||||
|
final String key = name.substring(0, name.indexOf("."));
|
||||||
|
titleView.setText(myResource.getResource(key).getValue());
|
||||||
|
|
||||||
|
final View previewWidget =
|
||||||
|
view.findViewById(R.id.background_predefined_item_preview);
|
||||||
|
try {
|
||||||
|
previewWidget.setBackgroundDrawable(
|
||||||
|
new BitmapDrawable(getResources(), getItem(position).getInputStream())
|
||||||
);
|
);
|
||||||
for (ZLFile f : WallpapersUtil.predefinedWallpaperFiles()) {
|
} catch (Throwable t) {
|
||||||
final String name = f.getShortName();
|
|
||||||
adapter.add(myResource.getResource(name.substring(0, name.indexOf("."))).getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
adapter.addAll(WallpapersUtil.predefinedWallpaperFiles());
|
||||||
setListAdapter(adapter);
|
setListAdapter(adapter);
|
||||||
getListView().setOnItemClickListener(this);
|
getListView().setOnItemClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public final void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
System.err.println("CLICKED:" + position);
|
setResult(RESULT_OK, new Intent().putExtra(
|
||||||
switch (position) {
|
BackgroundPreference.VALUE_KEY,
|
||||||
case 0:
|
((ZLFile)getListAdapter().getItem(position)).getPath()
|
||||||
break;
|
));
|
||||||
case 1:
|
finish();
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue