Skip to content

Commit

Permalink
first_version
Browse files Browse the repository at this point in the history
  • Loading branch information
vladexologija committed Nov 19, 2012
1 parent b3dbf6c commit ecff1f5
Show file tree
Hide file tree
Showing 23 changed files with 317 additions and 0 deletions.
22 changes: 22 additions & 0 deletions AndroidManifest.xml
@@ -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 added libs/android-support-v4.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions lint.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="ParserError" severity="ignore" />
</lint>
40 changes: 40 additions & 0 deletions proguard.cfg
@@ -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 *;
}
11 changes: 11 additions & 0 deletions project.properties
@@ -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
Binary file added res/drawable-hdpi/ic_1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_10.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_2.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_3.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_4.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_5.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_6.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_7.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_8.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_9.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions res/layout/item.xml
@@ -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"/>
27 changes: 27 additions & 0 deletions res/layout/items_list.xml
@@ -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>
4 changes: 4 additions & 0 deletions res/values/strings.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">PinterestListView</string>
</resources>
122 changes: 122 additions & 0 deletions src/com/vladimir/pinterestlistview/ItemsActivity.java
@@ -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 src/com/vladimir/pinterestlistview/adapters/ItemsAdapter.java
@@ -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;
}
}

0 comments on commit ecff1f5

Please sign in to comment.