1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 09:49:19 +02:00

works predefined image selector

This commit is contained in:
Nikolay Pultsin 2014-08-26 06:47:11 +04:00
parent a1b8286a02
commit 15100ec9a2
7 changed files with 113 additions and 27 deletions

View file

@ -4,6 +4,7 @@
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:paddingLeft="10dip"
>
<TextView
android:id="@+id/background_chooser_item_title"

View 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>

View file

@ -9,7 +9,7 @@
android:paddingBottom="10dip"
android:orientation="horizontal"
>
<yuku.ambilwarna.widget.AmbilWarnaPrefWidgetView
<yuku.ambilwarna.widget.AmbilWarnaPrefWidgetView
android:id="@+id/style_item_color"
android:layout_width="24dp"
android:layout_height="24dp"

View file

@ -60,6 +60,8 @@ import org.geometerplus.android.util.DeviceType;
public class PreferenceActivity extends ZLPreferenceActivity {
private final ActivityNetworkContext myNetworkContext = new ActivityNetworkContext(this);
private final FileChooserCollection myChooserCollection = new FileChooserCollection(this, 2000);
private static final int BACKGROUND_REQUEST_CODE = 3000;
private BackgroundPreference myBackgroundPreference;
public PreferenceActivity() {
super("Preferences");
@ -77,9 +79,18 @@ public class PreferenceActivity extends ZLPreferenceActivity {
return;
}
if (resultCode == RESULT_OK) {
myChooserCollection.update(requestCode, data);
if (resultCode != RESULT_OK) {
return;
}
if (BACKGROUND_REQUEST_CODE == requestCode) {
if (myBackgroundPreference != null) {
myBackgroundPreference.update(data);
}
return;
}
myChooserCollection.update(requestCode, data);
}
@Override
@ -448,9 +459,13 @@ public class PreferenceActivity extends ZLPreferenceActivity {
final Screen colorsScreen = createPreferenceScreen("colors");
colorsScreen.addPreference(new BackgroundPreference(
this, profile, colorsScreen.Resource.getResource("background")
));
myBackgroundPreference = new BackgroundPreference(
this,
profile,
colorsScreen.Resource.getResource("background"),
BACKGROUND_REQUEST_CODE
);
colorsScreen.addPreference(myBackgroundPreference);
final WallpaperPreference wallpaperPreference = new WallpaperPreference(
this, profile, colorsScreen.Resource.getResource("background")
) {

View file

@ -36,15 +36,19 @@ import org.geometerplus.zlibrary.ui.android.util.ZLAndroidColorUtil;
import org.geometerplus.fbreader.fbreader.options.ColorProfile;
public class BackgroundPreference extends Preference {
static final String VALUE_KEY = "fbreader.background.value";
private final ZLResource myResource;
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);
setWidgetLayoutResource(R.layout.background_preference);
myResource = resource;
myProfile = profile;
myRequestCode = requestCode;
}
@Override
@ -87,6 +91,14 @@ public class BackgroundPreference extends Preference {
@Override
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();
}
}

View file

@ -49,9 +49,10 @@ public class Chooser extends ListActivity implements AdapterView.OnItemClickList
}
public final void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.err.println("CLICKED:" + position);
switch (position) {
case 0:
setResult(RESULT_OK, new Intent().putExtra(BackgroundPreference.VALUE_KEY, ""));
finish();
break;
case 1:
startActivityForResult(new Intent(this, PredefinedImages.class), 1);
@ -61,4 +62,12 @@ public class Chooser extends ListActivity implements AdapterView.OnItemClickList
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
setResult(RESULT_OK, data);
finish();
}
}
}

View file

@ -20,9 +20,11 @@
package org.geometerplus.android.fbreader.preferences.background;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.view.ViewGroup;
import android.widget.*;
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.resources.ZLResource;
@ -37,26 +39,40 @@ public class PredefinedImages extends ListActivity implements AdapterView.OnItem
protected void onStart() {
super.onStart();
setTitle(myResource.getValue());
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, R.layout.background_chooser_item, R.id.background_chooser_item_title
);
for (ZLFile f : WallpapersUtil.predefinedWallpaperFiles()) {
final String name = f.getShortName();
adapter.add(myResource.getResource(name.substring(0, name.indexOf("."))).getValue());
}
final ArrayAdapter<ZLFile> adapter = new ArrayAdapter<ZLFile>(
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())
);
} catch (Throwable t) {
}
return view;
}
};
adapter.addAll(WallpapersUtil.predefinedWallpaperFiles());
setListAdapter(adapter);
getListView().setOnItemClickListener(this);
}
public final void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.err.println("CLICKED:" + position);
switch (position) {
case 0:
break;
case 1:
break;
case 2:
break;
}
setResult(RESULT_OK, new Intent().putExtra(
BackgroundPreference.VALUE_KEY,
((ZLFile)getListAdapter().getItem(position)).getPath()
));
finish();
}
}