Permalink
Browse files

ResizableLinearLayout is created.

  • Loading branch information...
cattaka committed Dec 24, 2012
1 parent ff07483 commit 679f7125b045ecf51886681e6d15eb075016aee2
Showing with 430 additions and 0 deletions.
  1. +8 −0 LibCtkView/.classpath
  2. +2 −0 LibCtkView/.gitignore
  3. +33 −0 LibCtkView/.project
  4. +14 −0 LibCtkView/AndroidManifest.xml
  5. BIN LibCtkView/ic_launcher-web.png
  6. +20 −0 LibCtkView/proguard-project.txt
  7. +15 −0 LibCtkView/project.properties
  8. BIN LibCtkView/res/drawable-hdpi/ic_launcher.png
  9. BIN LibCtkView/res/drawable-ldpi/ic_launcher.png
  10. BIN LibCtkView/res/drawable-mdpi/ic_launcher.png
  11. BIN LibCtkView/res/drawable-xhdpi/ic_launcher.png
  12. +5 −0 LibCtkView/res/values-v11/styles.xml
  13. +5 −0 LibCtkView/res/values-v14/styles.xml
  14. +3 −0 LibCtkView/res/values/strings.xml
  15. +5 −0 LibCtkView/res/values/styles.xml
  16. +120 −0 LibCtkView/src/net/cattaka/android/ctkview/ResizableLinearLayout.java
  17. +8 −0 LibCtkViewSample/.classpath
  18. +2 −0 LibCtkViewSample/.gitignore
  19. +33 −0 LibCtkViewSample/.project
  20. +25 −0 LibCtkViewSample/AndroidManifest.xml
  21. BIN LibCtkViewSample/ic_launcher-web.png
  22. +20 −0 LibCtkViewSample/proguard-project.txt
  23. +15 −0 LibCtkViewSample/project.properties
  24. BIN LibCtkViewSample/res/drawable-hdpi/ic_action_search.png
  25. BIN LibCtkViewSample/res/drawable-hdpi/ic_launcher.png
  26. BIN LibCtkViewSample/res/drawable-ldpi/ic_launcher.png
  27. BIN LibCtkViewSample/res/drawable-mdpi/ic_action_search.png
  28. BIN LibCtkViewSample/res/drawable-mdpi/ic_launcher.png
  29. BIN LibCtkViewSample/res/drawable-xhdpi/ic_action_search.png
  30. BIN LibCtkViewSample/res/drawable-xhdpi/ic_launcher.png
  31. +48 −0 LibCtkViewSample/res/layout/activity_main.xml
  32. +6 −0 LibCtkViewSample/res/menu/activity_main.xml
  33. +5 −0 LibCtkViewSample/res/values-v11/styles.xml
  34. +5 −0 LibCtkViewSample/res/values-v14/styles.xml
  35. +8 −0 LibCtkViewSample/res/values/strings.xml
  36. +5 −0 LibCtkViewSample/res/values/styles.xml
  37. +20 −0 LibCtkViewSample/src/com/example/libctkviewsample/MainActivity.java
View
@@ -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>
View
@@ -0,0 +1,2 @@
+/bin
+/gen
View
@@ -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>
@@ -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 not shown.
@@ -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 *;
+#}
@@ -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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Holo.Light" />
+
+</resources>
@@ -0,0 +1,5 @@
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
+
+</resources>
@@ -0,0 +1,3 @@
+<resources>
+ <string name="app_name">LibCtkView</string>
+</resources>
@@ -0,0 +1,5 @@
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Light" />
+
+</resources>
@@ -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);
+ }
+}
@@ -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>
@@ -0,0 +1,2 @@
+/bin
+/gen
View
@@ -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>
@@ -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 not shown.
@@ -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 *;
+#}
@@ -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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.

0 comments on commit 679f712

Please sign in to comment.