Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use attrs for max display height

  • Loading branch information...
commit a34beeb21b11fda89e45085f5e86d0fc05b196d5 1 parent afe1de0
@Xlythe authored
View
24 res/values/attrs.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* Copyright 2008, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<resources>
+ <declare-styleable name="ScrollableDisplay">
+ <!-- Used to limit the height of Scrollable Display -->
+ <attr name="max_height" format="dimension" />
+ </declare-styleable>
+</resources>
View
4 res/values/styles.xml
@@ -13,7 +13,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<resources xmlns:android="http://schemas.android.com/apk/res/android">
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:calculator="http://schemas.android.com/apk/res/com.android2.calculator3">
<dimen name="btn_digit_text_size">40sp</dimen>
<dimen name="btn_operation_text_size">40sp</dimen>
<dimen name="btn_function_text_size">30sp</dimen>
@@ -64,6 +65,7 @@
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:paddingBottom">8dp</item>
+ <item name="max_height">@dimen/max_display_height</item>
</style>
<style name="btn_row_style">
View
19 src/com/android2/calculator3/view/ScrollableDisplay.java
@@ -1,6 +1,7 @@
package com.android2.calculator3.view;
import android.content.Context;
+import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
@@ -14,9 +15,15 @@
private int mMaxHeight;
public ScrollableDisplay(Context context, AttributeSet attrs) {
- super(context, attrs);
+ this(context, attrs, 0);
+ }
+
+ public ScrollableDisplay(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrollableDisplay, defStyle, 0);
+ setMaxHeight(a.getDimensionPixelSize(R.styleable.ScrollableDisplay_max_height, -1));
+ a.recycle();
addView(new AdvancedDisplay(context));
- setMaxHeight((int) getContext().getResources().getDimension(R.dimen.max_display_height));
setOnLongClickListener(this);
}
@@ -43,10 +50,12 @@ public void setMaxHeight(int maxHeight) {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- int width = getMeasuredWidth();
- int height = Math.min(getMeasuredHeight(), mMaxHeight);
+ if(mMaxHeight != -1) {
+ int width = getMeasuredWidth();
+ int height = Math.min(getMeasuredHeight(), mMaxHeight);
- setMeasuredDimension(width, height);
+ setMeasuredDimension(width, height);
+ }
}
private int getScrollRange() {
Please sign in to comment.
Something went wrong with that request. Please try again.