Skip to content

Commit

Permalink
ResizableLinearLayout is created.
Browse files Browse the repository at this point in the history
  • Loading branch information
cattaka committed Dec 24, 2012
1 parent ff07483 commit 679f712
Show file tree
Hide file tree
Showing 37 changed files with 430 additions and 0 deletions.
8 changes: 8 additions & 0 deletions LibCtkView/.classpath
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
2 changes: 2 additions & 0 deletions LibCtkView/.gitignore
@@ -0,0 +1,2 @@
/bin
/gen
33 changes: 33 additions & 0 deletions LibCtkView/.project
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>LibCtkView</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
14 changes: 14 additions & 0 deletions LibCtkView/AndroidManifest.xml
@@ -0,0 +1,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.libctkview"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />

<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme">

</application>

</manifest>
Binary file added LibCtkView/ic_launcher-web.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions LibCtkView/proguard-project.txt
@@ -0,0 +1,20 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
15 changes: 15 additions & 0 deletions LibCtkView/project.properties
@@ -0,0 +1,15 @@
# 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 edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-16
android.library=true
Binary file added LibCtkView/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 LibCtkView/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 LibCtkView/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.
Binary file added LibCtkView/res/drawable-xhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions LibCtkView/res/values-v11/styles.xml
@@ -0,0 +1,5 @@
<resources>

<style name="AppTheme" parent="android:Theme.Holo.Light" />

</resources>
5 changes: 5 additions & 0 deletions LibCtkView/res/values-v14/styles.xml
@@ -0,0 +1,5 @@
<resources>

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />

</resources>
3 changes: 3 additions & 0 deletions LibCtkView/res/values/strings.xml
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">LibCtkView</string>
</resources>
5 changes: 5 additions & 0 deletions LibCtkView/res/values/styles.xml
@@ -0,0 +1,5 @@
<resources>

<style name="AppTheme" parent="android:Theme.Light" />

</resources>
120 changes: 120 additions & 0 deletions LibCtkView/src/net/cattaka/android/ctkview/ResizableLinearLayout.java
@@ -0,0 +1,120 @@

package net.cattaka.android.ctkview;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Shader;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.Shape;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class ResizableLinearLayout extends LinearLayout {
private List<View> mSliders = new ArrayList<View>();

private float mSliderWidth;

private ShapeDrawable mDrawable;

private OnTouchListener mOnTouchListener = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (mSliders.contains(v)) {
int idx = indexOfChild(v);
if (idx < 1 || getChildCount() - 1 <= idx) {
return false;
}
View upper = getChildAt(idx - 1);
View lower = getChildAt(idx + 1);
LayoutParams upperParams = (LayoutParams)upper.getLayoutParams();
LayoutParams lowerParams = (LayoutParams)lower.getLayoutParams();
float rate;
if (getOrientation() == LinearLayout.VERTICAL) {
int top = upper.getTop();
int bottom = lower.getBottom();
float y = event.getY() + v.getTop();
rate = (y - top) / (float)(bottom - top);
} else {
int left = upper.getLeft();
int right = lower.getRight();
float x = event.getX() + v.getLeft();
rate = (x - left) / (float)(right - left);
}
float weight = upperParams.weight + lowerParams.weight;
if (weight == 0) {
weight = 1;
}
upperParams.weight = rate * weight;
lowerParams.weight = (1.0f - rate) * weight;
upper.setLayoutParams(upperParams);
lower.setLayoutParams(lowerParams);
}
return false;
}
};

public ResizableLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}

public ResizableLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public ResizableLinearLayout(Context context) {
super(context);
init();
}

private void init() {
mSliderWidth = 20 * getContext().getResources().getDisplayMetrics().density;

final Paint myPaint = new Paint();
Shader s = new LinearGradient(0, 0, 0, mSliderWidth, Color.LTGRAY, Color.GRAY,
Shader.TileMode.CLAMP);

myPaint.setStrokeWidth(1);
myPaint.setColor(0xFF000000);
myPaint.setStyle(Style.FILL);
myPaint.setShader(s);
Shape shape = new Shape() {
@Override
public void draw(Canvas canvas, Paint paint) {
canvas.drawColor(Color.LTGRAY);
canvas.drawRect(2, 2, canvas.getWidth() - 4, canvas.getHeight() - 4, myPaint);
}
};
mDrawable = new ShapeDrawable(shape);
}

@Override
public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) {
if (getChildCount() > 0) {
Button slider = new Button(getContext());
slider.setBackgroundDrawable(mDrawable);
slider.setOnTouchListener(mOnTouchListener);
mSliders.add(slider);

LayoutParams sliderParams;
if (getOrientation() == LinearLayout.VERTICAL) {
sliderParams = new LayoutParams(LayoutParams.MATCH_PARENT, (int)mSliderWidth);
} else {
sliderParams = new LayoutParams((int)mSliderWidth, LayoutParams.MATCH_PARENT);
}
super.addView(slider, index, sliderParams);
}
super.addView(child, index, params);
}
}
8 changes: 8 additions & 0 deletions LibCtkViewSample/.classpath
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
2 changes: 2 additions & 0 deletions LibCtkViewSample/.gitignore
@@ -0,0 +1,2 @@
/bin
/gen
33 changes: 33 additions & 0 deletions LibCtkViewSample/.project
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>LibCtkViewSample</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
25 changes: 25 additions & 0 deletions LibCtkViewSample/AndroidManifest.xml
@@ -0,0 +1,25 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.libctkviewsample"
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"
android:theme="@style/AppTheme" >
<activity
android:name=".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 LibCtkViewSample/ic_launcher-web.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions LibCtkViewSample/proguard-project.txt
@@ -0,0 +1,20 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
15 changes: 15 additions & 0 deletions LibCtkViewSample/project.properties
@@ -0,0 +1,15 @@
# 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 edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-16
android.library.reference.1=../LibCtkView
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.

0 comments on commit 679f712

Please sign in to comment.