Skip to content

Commit

Permalink
Internationalization & fixedx issues with UIL
Browse files Browse the repository at this point in the history
  • Loading branch information
aizaz committed Mar 16, 2015
1 parent 4c245c7 commit bc02090
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
10 changes: 5 additions & 5 deletions res/layout/activity_photoselector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:text="返回"
android:text="@string/back"
android:textColor="#FEFEFE"
android:textSize="@dimen/layout_title_mini_textsize"
android:visibility="invisible" />
Expand All @@ -46,7 +46,7 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical"
android:text="选择照片"
android:text="@string/select_photos"
android:textColor="@android:color/white"
android:textSize="18sp" />

Expand All @@ -62,7 +62,7 @@
android:paddingLeft="10dp"
android:paddingRight="0dp"
android:paddingTop="5dp"
android:text="确定"
android:text="@string/sure"
android:textColor="@android:color/white"
android:textSize="@dimen/layout_title_mini_textsize" />

Expand Down Expand Up @@ -136,7 +136,7 @@
android:layout_marginLeft="10dp"
android:gravity="left|center_vertical"
android:minWidth="50dp"
android:text="最近照片"
android:text="@string/recent_photos"
android:textColor="@drawable/btn_black_textcolor_selector"
android:textSize="13sp" />

Expand Down Expand Up @@ -170,7 +170,7 @@
android:clickable="true"
android:enabled="false"
android:padding="10dp"
android:text="预览"
android:text="@string/preview"
android:textColor="@android:color/white" />
</RelativeLayout>

Expand Down
10 changes: 5 additions & 5 deletions res/layout/view_camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
android:id="@+id/tv_camera_vc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@drawable/bg_dark_selector"
android:drawableTop="@drawable/btn_camera_selector"
android:clickable="true"
android:drawablePadding="0dp"
android:drawableTop="@drawable/btn_camera_selector"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="15dp"
android:text="拍摄照片"
android:textColor="@android:color/white"
android:orientation="vertical" />
android:text="@string/taking_pictures"
android:textColor="@android:color/white" />
14 changes: 14 additions & 0 deletions res/values-zh/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">PhotoSelector</string>
<string name="more_than_max">超过了上限</string>
<string name="preview">预览</string>
<string name="recent_photos">最近照片</string>
<string name="sure">确定</string>
<string name="select_photos">选择照片</string>
<string name="back">返回</string>
<string name="taking_pictures">拍摄照片</string>
<string name="max_img_limit_reached">不能选择超过%d个图像</string>

</resources>
12 changes: 10 additions & 2 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">PhotoSelector</string>
<string name="app_name">UltraPhotoSelector</string>
<string name="more_than_max">Exceeds the upper limit</string>
<string name="preview">Preview</string>
<string name="recent_photos">Recent photos</string>
<string name="sure">Sure</string>
<string name="select_photos">Select photos</string>
<string name="back">Back</string>
<string name="taking_pictures">Taking Pictures</string>
<string name="max_img_limit_reached">Cannot select more than %d images</string>

</resources>
</resources>
12 changes: 2 additions & 10 deletions src/com/photoselector/ui/PhotoItem.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.photoselector.ui;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.view.LayoutInflater;
Expand All @@ -13,7 +12,6 @@
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.photoselector.R;
import com.photoselector.model.PhotoModel;
Expand All @@ -32,13 +30,7 @@ public class PhotoItem extends LinearLayout implements OnCheckedChangeListener,
private PhotoModel photo;
private boolean isCheckAll;
private onItemClickListener l;
private int position;

public static DisplayImageOptions imageOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_picture_loading)
.showImageOnFail(R.drawable.ic_picture_loadfailed)
.cacheInMemory(true).cacheOnDisk(true).considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565).build();
private int position;

private PhotoItem(Context context) {
super(context);
Expand Down Expand Up @@ -86,7 +78,7 @@ public void setImageDrawable(final PhotoModel photo) {
*/

ImageLoader.getInstance().displayImage(
"file://" + photo.getOriginalPath(), ivPhoto, imageOptions);
"file://" + photo.getOriginalPath(), ivPhoto);
}

private void setDrawingable() {
Expand Down
63 changes: 60 additions & 3 deletions src/com/photoselector/ui/PhotoSelectorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
Expand All @@ -20,9 +21,16 @@
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.decode.BaseImageDecoder;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.nostra13.universalimageloader.utils.StorageUtils;
import com.photoselector.R;
import com.photoselector.domain.PhotoSelectorDomain;
import com.photoselector.model.AlbumModel;
Expand All @@ -47,7 +55,7 @@ public class PhotoSelectorActivity extends Activity implements
public static final int REQUEST_PHOTO = 0;
private static final int REQUEST_CAMERA = 1;

public static final String RECCENT_PHOTO = "最近照片";
public static String RECCENT_PHOTO = null;

private GridView gvPhotos;
private ListView lvAblum;
Expand All @@ -63,13 +71,16 @@ public class PhotoSelectorActivity extends Activity implements
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RECCENT_PHOTO = getResources().getString(R.string.recent_photos);
requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
setContentView(R.layout.activity_photoselector);

if (getIntent().getExtras() != null) {
MAX_IMAGE = getIntent().getIntExtra(KEY_MAX, 10);
}

initImageLoader();

photoSelectorDomain = new PhotoSelectorDomain(getApplicationContext());

selected = new ArrayList<PhotoModel>();
Expand Down Expand Up @@ -103,6 +114,48 @@ protected void onCreate(Bundle savedInstanceState) {
photoSelectorDomain.updateAlbum(albumListener); // 跟新相册信息
}

private void initImageLoader() {
DisplayImageOptions imageOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_picture_loading)
.showImageOnFail(R.drawable.ic_picture_loadfailed)
.cacheInMemory(true).cacheOnDisk(true)
.resetViewBeforeLoading(true).considerExifParams(false)
.bitmapConfig(Bitmap.Config.RGB_565).build();

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
this)
.memoryCacheExtraOptions(400, 400)
// default = device screen dimensions
.diskCacheExtraOptions(400, 400, null)
.threadPoolSize(5)
// default Thread.NORM_PRIORITY - 1
.threadPriority(Thread.NORM_PRIORITY)
// default FIFO
.tasksProcessingOrder(QueueProcessingType.LIFO)
// default
.denyCacheImageMultipleSizesInMemory()
.memoryCache(new LruMemoryCache(2 * 1024 * 1024))
.memoryCacheSize(2 * 1024 * 1024)
.memoryCacheSizePercentage(13)
// default
.diskCache(
new UnlimitedDiscCache(StorageUtils.getCacheDirectory(
this, true)))
// default
.diskCacheSize(50 * 1024 * 1024).diskCacheFileCount(100)
.diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
// default
.imageDownloader(new BaseImageDownloader(this))
// default
.imageDecoder(new BaseImageDecoder(false))
// default
.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
// default
.defaultDisplayImageOptions(imageOptions).build();

ImageLoader.getInstance().init(config);
}

@Override
public void onClick(View v) {
if (v.getId() == R.id.btn_right_lh)
Expand Down Expand Up @@ -136,7 +189,11 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// selected photos
// ///////////////////////////////////////////////////////////////////////////////////////////
if (selected.size() >= MAX_IMAGE) {
Toast.makeText(this, "已超出最大数量", Toast.LENGTH_SHORT).show();
Toast.makeText(
this,
String.format(
getString(R.string.max_img_limit_reached),
MAX_IMAGE), Toast.LENGTH_SHORT).show();
photoModel.setChecked(false);
photoAdapter.notifyDataSetChanged();
} else {
Expand Down Expand Up @@ -225,7 +282,7 @@ public void onCheckedChanged(PhotoModel photoModel,

if (selected.isEmpty()) {
tvPreview.setEnabled(false);
tvPreview.setText("预览");
tvPreview.setText(getString(R.string.preview));
}
}

Expand Down

0 comments on commit bc02090

Please sign in to comment.