Skip to content

Commit

Permalink
Enhancements #2 and #8
Browse files Browse the repository at this point in the history
Also added ScaleGestureDetector, if available.
Reorganized example for files and URLs.
Added example pictures.
Updated v4.jar
  • Loading branch information
RomanTruba committed Jan 31, 2013
1 parent d2ce306 commit a1ef8c9
Show file tree
Hide file tree
Showing 23 changed files with 608 additions and 106 deletions.
45 changes: 31 additions & 14 deletions example/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.truba.touchgallery">
<uses-sdk android:minSdkVersion="4"/>
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".GalleryActivity" android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.truba.touchgallery" >

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.INTERNET" />

<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:allowBackup="false" >
<activity
android:name="ru.truba.touchgallery.GalleryUrlActivity"
android:configChanges="orientation" >
</activity>
<activity
android:name="ru.truba.touchgallery.GalleryFileActivity"
android:configChanges="orientation" >
</activity>
<activity
android:name="ru.truba.touchgallery.MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Binary file added example/assets/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions example/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>
2 changes: 1 addition & 1 deletion example/project.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is automatically generated by IntelliJ IDEA
# Project target.
target=android-8
target=android-17
android.library.reference.1=../library
14 changes: 14 additions & 0 deletions example/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />

</RelativeLayout>
9 changes: 9 additions & 0 deletions example/res/menu/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/menu_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/menu_settings"/>

</menu>
10 changes: 8 additions & 2 deletions example/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<resources>
<string name="app_name">TouchGallery</string>
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">TouchGallery</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">Main Activity</string>

</resources>
76 changes: 76 additions & 0 deletions example/src/ru/truba/touchgallery/GalleryFileActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright (c) 2012 Roman Truba
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package ru.truba.touchgallery;

import android.app.Activity;
import android.os.Bundle;
import ru.truba.touchgallery.GalleryWidget.FilePagerAdapter;
import ru.truba.touchgallery.GalleryWidget.GalleryViewPager;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

public class GalleryFileActivity extends Activity {

private GalleryViewPager mViewPager;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

String[] urls = null;
List<String> items = new ArrayList<String>();
try {
urls = getAssets().list("");

for (String filename : urls)
{
if (filename.matches(".+\\.jpg"))
{
String path = getFilesDir() + "/" + filename;
copy(getAssets().open(filename), new File(path) );
items.add(path);
}
}
} catch (IOException e) {
e.printStackTrace();
}

FilePagerAdapter pagerAdapter = new FilePagerAdapter(this, items);
mViewPager = (GalleryViewPager)findViewById(R.id.viewer);
mViewPager.setOffscreenPageLimit(3);
mViewPager.setAdapter(pagerAdapter);
}
public void copy(InputStream in, File dst) throws IOException {

OutputStream out = new FileOutputStream(dst);

// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Collections;
import java.util.List;

public class GalleryActivity extends Activity {
public class GalleryUrlActivity extends Activity {

private GalleryViewPager mViewPager;
public void onCreate(Bundle savedInstanceState) {
Expand Down
67 changes: 67 additions & 0 deletions example/src/ru/truba/touchgallery/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ru.truba.touchgallery;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class MainActivity extends ListActivity {

public static final String TITLE = "title";
public static final String SUBTITLE = "subtitle";

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

setListAdapter(createAdapter());
}

protected Map<String, String> createElement(String title, String subtitle)
{
Map<String, String> result = new HashMap<String, String>();
result.put(TITLE, title);
result.put(SUBTITLE, subtitle);
return result;
}
public List<Map<String, String>> getData()
{
List<Map<String, String>> result = new ArrayList<Map<String,String>>();
result.add(createElement("Web load", "In this example, you provide list of URLs to display in gallery"));
result.add(createElement("Local load", "In this example, you provide list of files to display in gallery"));
return result;
}
public ListAdapter createAdapter()
{
SimpleAdapter adapter = new SimpleAdapter(this, getData(),
android.R.layout.simple_list_item_2,
new String[]{TITLE, SUBTITLE},
new int[]{android.R.id.text1, android.R.id.text2});
return adapter;
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent i = null;
switch (position)
{
case 0:
i = new Intent(this, GalleryUrlActivity.class);
break;
case 1:
i = new Intent(this, GalleryFileActivity.class);
break;
}
startActivity(i);
}

}
11 changes: 1 addition & 10 deletions library/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.truba.touchgallery"
android:versionCode="1"
android:versionName="1.0">
android:versionName="1.1">

<uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="16" />

<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="ACTIVITY_ENTRY_NAME"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Binary file modified library/libs/android-support-v4.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion library/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

android.library=true
# Project target.
target=android-8
target=android-17
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Copyright (c) 2012 Roman Truba
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package ru.truba.touchgallery.GalleryWidget;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import ru.truba.touchgallery.TouchView.UrlTouchImageView;

/**
Class wraps URLs to adapter, then it instantiates <b>UrlTouchImageView</b> objects to paging up through them.
*/
public class BasePagerAdapter extends PagerAdapter {

protected final List<String> mResources;
protected final Context mContext;
public BasePagerAdapter()
{
mResources = null;
mContext = null;
}
public BasePagerAdapter(Context context, List<String> resources)
{
this.mResources = resources;
this.mContext = context;
}
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
super.setPrimaryItem(container, position, object);
GalleryViewPager galleryContainer = ((GalleryViewPager)container);
if (galleryContainer.mCurrentView != null) galleryContainer.mCurrentView.resetScale();
}

@Override
public void destroyItem(ViewGroup collection, int position, Object view){
collection.removeView((View) view);
}

@Override
public int getCount(){
return mResources.size();
}

@Override
public boolean isViewFromObject(View view, Object object){
return view.equals(object);
}

@Override
public void finishUpdate(ViewGroup arg0){
}

@Override
public void restoreState(Parcelable arg0, ClassLoader arg1){
}

@Override
public Parcelable saveState(){
return null;
}

@Override
public void startUpdate(ViewGroup arg0){
}

}
Loading

0 comments on commit a1ef8c9

Please sign in to comment.