Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vladexologija
committed
Nov 19, 2012
1 parent
b3dbf6c
commit ecff1f5
Showing
23 changed files
with
317 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.vladimir.pinterestlistview" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/> | ||
|
||
<application | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" > | ||
<activity | ||
android:name=".ItemsActivity" | ||
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 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<lint> | ||
<issue id="ParserError" severity="ignore" /> | ||
</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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
-optimizationpasses 5 | ||
-dontusemixedcaseclassnames | ||
-dontskipnonpubliclibraryclasses | ||
-dontpreverify | ||
-verbose | ||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* | ||
|
||
-keep public class * extends android.app.Activity | ||
-keep public class * extends android.app.Application | ||
-keep public class * extends android.app.Service | ||
-keep public class * extends android.content.BroadcastReceiver | ||
-keep public class * extends android.content.ContentProvider | ||
-keep public class * extends android.app.backup.BackupAgentHelper | ||
-keep public class * extends android.preference.Preference | ||
-keep public class com.android.vending.licensing.ILicensingService | ||
|
||
-keepclasseswithmembernames class * { | ||
native <methods>; | ||
} | ||
|
||
-keepclasseswithmembers class * { | ||
public <init>(android.content.Context, android.util.AttributeSet); | ||
} | ||
|
||
-keepclasseswithmembers class * { | ||
public <init>(android.content.Context, android.util.AttributeSet, int); | ||
} | ||
|
||
-keepclassmembers class * extends android.app.Activity { | ||
public void *(android.view.View); | ||
} | ||
|
||
-keepclassmembers enum * { | ||
public static **[] values(); | ||
public static ** valueOf(java.lang.String); | ||
} | ||
|
||
-keep class * implements android.os.Parcelable { | ||
public static final android.os.Parcelable$Creator *; | ||
} |
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,11 @@ | ||
# This file is automatically generated by Android Tools. | ||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! | ||
# | ||
# This file must be checked in Version Control Systems. | ||
# | ||
# To customize properties used by the Ant build system use, | ||
# "ant.properties", and override values to adapt the script to your | ||
# project structure. | ||
|
||
# Project target. | ||
target=android-14 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/item_image" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_centerHorizontal="true" | ||
android:adjustViewBounds="true" | ||
android:scaleType="fitCenter" | ||
android:paddingTop="10dp"/> |
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,27 @@ | ||
<?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="fill_parent" | ||
android:orientation="horizontal" | ||
android:paddingLeft="10dp" | ||
android:paddingRight="10dp" > | ||
|
||
<ListView | ||
android:id="@+id/list_view_left" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:layout_weight="1" | ||
android:paddingRight="5dp" | ||
android:scrollbars="none" > | ||
</ListView> | ||
|
||
<ListView | ||
android:id="@+id/list_view_right" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:layout_weight="1" | ||
android:paddingLeft="5dp" | ||
android:scrollbars="none" > | ||
</ListView> | ||
|
||
</LinearLayout> |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name">PinterestListView</string> | ||
</resources> |
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,122 @@ | ||
package com.vladimir.pinterestlistview; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.view.MotionEvent; | ||
import android.view.View; | ||
import android.view.View.OnTouchListener; | ||
import android.widget.AbsListView; | ||
import android.widget.AbsListView.OnScrollListener; | ||
import android.widget.ListView; | ||
|
||
import com.vladimir.pinterestlistview.adapters.ItemsAdapter; | ||
|
||
public class ItemsActivity extends Activity { | ||
|
||
private final String TAG = "FeedActivity"; | ||
|
||
private ListView listViewLeft; | ||
private ListView listViewRight; | ||
private ItemsAdapter leftAdapter; | ||
private ItemsAdapter rightAdapter; | ||
|
||
int[] leftViewsHeights; | ||
int[] rightViewsHeights; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.items_list); | ||
|
||
listViewLeft = (ListView) findViewById(R.id.list_view_left); | ||
listViewRight = (ListView) findViewById(R.id.list_view_right); | ||
|
||
loadItems(); | ||
|
||
listViewLeft.setOnTouchListener(touchListener); | ||
listViewRight.setOnTouchListener(touchListener); | ||
listViewLeft.setOnScrollListener(scrollListener); | ||
listViewRight.setOnScrollListener(scrollListener); | ||
} | ||
|
||
OnTouchListener touchListener = new OnTouchListener() { | ||
boolean dispatched = false; | ||
|
||
@Override | ||
public boolean onTouch(View v, MotionEvent event) { | ||
if (v.equals(listViewLeft) && !dispatched) { | ||
dispatched = true; | ||
listViewRight.dispatchTouchEvent(event); | ||
} else if (v.equals(listViewRight) && !dispatched) { | ||
dispatched = true; | ||
listViewLeft.dispatchTouchEvent(event); | ||
} | ||
|
||
dispatched = false; | ||
return false; | ||
} | ||
}; | ||
|
||
OnScrollListener scrollListener = new OnScrollListener() { | ||
|
||
@Override | ||
public void onScrollStateChanged(AbsListView v, int scrollState) { | ||
} | ||
|
||
@Override | ||
public void onScroll(AbsListView view, int firstVisibleItem, | ||
int visibleItemCount, int totalItemCount) { | ||
|
||
if (view.getChildAt(0) != null) { | ||
if (view.equals(listViewLeft) ){ | ||
leftViewsHeights[view.getFirstVisiblePosition()] = view.getChildAt(0).getHeight(); | ||
|
||
int h = 0; | ||
for (int i = 0; i < listViewRight.getFirstVisiblePosition(); i++) { | ||
h += rightViewsHeights[i]; | ||
} | ||
|
||
int hi = 0; | ||
for (int i = 0; i < listViewLeft.getFirstVisiblePosition(); i++) { | ||
hi += leftViewsHeights[i]; | ||
} | ||
|
||
int top = h - hi + view.getChildAt(0).getTop(); | ||
listViewRight.setSelectionFromTop(listViewRight.getFirstVisiblePosition(), top); | ||
} else if (view.equals(listViewRight)) { | ||
rightViewsHeights[view.getFirstVisiblePosition()] = view.getChildAt(0).getHeight(); | ||
|
||
int h = 0; | ||
for (int i = 0; i < listViewLeft.getFirstVisiblePosition(); i++) { | ||
h += leftViewsHeights[i]; | ||
} | ||
|
||
int hi = 0; | ||
for (int i = 0; i < listViewRight.getFirstVisiblePosition(); i++) { | ||
hi += rightViewsHeights[i]; | ||
} | ||
|
||
int top = h - hi + view.getChildAt(0).getTop(); | ||
listViewLeft.setSelectionFromTop(listViewLeft.getFirstVisiblePosition(), top); | ||
} | ||
|
||
} | ||
|
||
} | ||
}; | ||
|
||
private void loadItems(){ | ||
Integer[] leftItems = new Integer[]{R.drawable.ic_1, R.drawable.ic_2, R.drawable.ic_3, R.drawable.ic_4, R.drawable.ic_5}; | ||
Integer[] rightItems = new Integer[]{R.drawable.ic_6, R.drawable.ic_7, R.drawable.ic_8, R.drawable.ic_9, R.drawable.ic_10}; | ||
|
||
leftAdapter = new ItemsAdapter(this, R.layout.item, leftItems); | ||
rightAdapter = new ItemsAdapter(this, R.layout.item, rightItems); | ||
listViewLeft.setAdapter(leftAdapter); | ||
listViewRight.setAdapter(rightAdapter); | ||
|
||
leftViewsHeights = new int[leftItems.length]; | ||
rightViewsHeights = new int[rightItems.length]; | ||
} | ||
|
||
|
||
} |
78 changes: 78 additions & 0 deletions
78
src/com/vladimir/pinterestlistview/adapters/ItemsAdapter.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,78 @@ | ||
package com.vladimir.pinterestlistview.adapters; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.res.Resources; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.util.DisplayMetrics; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.ImageView; | ||
import android.widget.RelativeLayout; | ||
|
||
public class ItemsAdapter extends ArrayAdapter<Integer>{ | ||
|
||
Context context; | ||
LayoutInflater inflater; | ||
int layoutResourceId; | ||
int imageWidth; | ||
|
||
public ItemsAdapter(Context context, int layoutResourceId, Integer[] items) { | ||
super(context, layoutResourceId, items); | ||
this.context = context; | ||
this.layoutResourceId = layoutResourceId; | ||
|
||
int width = ((Activity)context).getWindowManager().getDefaultDisplay().getWidth(); | ||
int margin = (int)convertDpToPixel(10f, (Activity)context); | ||
imageWidth = (width - (3 * margin)); | ||
} | ||
|
||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
ImageView row = (ImageView) convertView; | ||
ItemHolder holder; | ||
Integer item = getItem(position); | ||
|
||
if (row == null) { | ||
holder = new ItemHolder(); | ||
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | ||
row = (ImageView) inflater.inflate(layoutResourceId, parent, false); | ||
holder.itemImage = row; | ||
} else { | ||
holder = (ItemHolder) row.getTag(); | ||
} | ||
|
||
row.setTag(holder); | ||
setImageBitmap(item, holder.itemImage); | ||
return row; | ||
} | ||
|
||
|
||
private void setImageBitmap(Integer item, ImageView imageView){ | ||
Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), item); | ||
if (imageWidth != 0){ | ||
float i = ((float)imageWidth)/((float)bitmap.getWidth()); | ||
float imageHeight = i * (bitmap.getHeight()); | ||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) imageView.getLayoutParams(); | ||
params.height = (int) imageHeight; | ||
params.width = imageWidth; | ||
imageView.setLayoutParams(params); | ||
} | ||
imageView.setImageBitmap(bitmap); | ||
} | ||
|
||
public static float convertDpToPixel(float dp, Context context){ | ||
Resources resources = context.getResources(); | ||
DisplayMetrics metrics = resources.getDisplayMetrics(); | ||
float px = dp * (metrics.densityDpi/160f); | ||
return px; | ||
} | ||
|
||
public static class ItemHolder | ||
{ | ||
ImageView itemImage; | ||
} | ||
} |