-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also added ScaleGestureDetector, if available. Reorganized example for files and URLs. Added example pictures. Updated v4.jar
- Loading branch information
1 parent
d2ce306
commit a1ef8c9
Showing
23 changed files
with
608 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<lint> | ||
</lint> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
76
example/src/ru/truba/touchgallery/GalleryFileActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
|
||
android.library=true | ||
# Project target. | ||
target=android-8 | ||
target=android-17 |
86 changes: 86 additions & 0 deletions
86
library/src/ru/truba/touchgallery/GalleryWidget/BasePagerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ | ||
} | ||
|
||
} |
Oops, something went wrong.