mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 23:36:47 +00:00
clean up rollo / launcher2
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
|
||||
launcher:cellWidth="106dip"
|
||||
launcher:cellHeight="73dip"
|
||||
launcher:cellWidth="@dimen/workspace_cell_width"
|
||||
launcher:cellHeight="@dimen/workspace_cell_height"
|
||||
launcher:longAxisStartPadding="0dip"
|
||||
launcher:longAxisEndPadding="55dip"
|
||||
launcher:shortAxisStartPadding="0dip"
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
|
||||
launcher:cellWidth="80dip"
|
||||
launcher:cellHeight="100dip"
|
||||
launcher:cellWidth="@dimen/workspace_cell_width"
|
||||
launcher:cellHeight="@dimen/workspace_cell_height"
|
||||
launcher:longAxisStartPadding="0dip"
|
||||
launcher:longAxisEndPadding="55dip"
|
||||
launcher:shortAxisStartPadding="0dip"
|
||||
|
||||
@@ -128,12 +128,12 @@ int main(void* con, int ft, int launchID)
|
||||
if (alpha > 0) {
|
||||
color(1.0f, 1.0f, 1.0f, alpha);
|
||||
|
||||
float ty = 605.f - y * 150.f;
|
||||
float ty = 654.f - y * 150.f;
|
||||
|
||||
ty = ty + 0.25f;
|
||||
|
||||
bindTexture(NAMED_PFText, 0, loadI32(3, index));
|
||||
drawRect(tx, ty, tx + 128.f, ty + 32.f, 0.5f);
|
||||
drawRect(tx, ty, tx + 128.f, ty + 64.f, 0.5f);
|
||||
}
|
||||
iconCount--;
|
||||
index++;
|
||||
|
||||
20
res/values-land/dimens.xml
Normal file
20
res/values-land/dimens.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 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>
|
||||
<dimen name="workspace_cell_width">106dip</dimen>
|
||||
<dimen name="workspace_cell_height">73dip</dimen>
|
||||
</resources>
|
||||
20
res/values-port/dimens.xml
Normal file
20
res/values-port/dimens.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 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>
|
||||
<dimen name="workspace_cell_width">80dip</dimen>
|
||||
<dimen name="workspace_cell_height">100dip</dimen>
|
||||
</resources>
|
||||
@@ -40,7 +40,6 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
@@ -232,6 +231,7 @@ public class AllAppsView extends RSSurfaceView {
|
||||
}
|
||||
|
||||
public class RolloRS {
|
||||
|
||||
//public static final int STATE_SELECTED_ID = 0;
|
||||
public static final int STATE_DONE = 1;
|
||||
//public static final int STATE_PRESSURE = 2;
|
||||
@@ -243,7 +243,6 @@ public class AllAppsView extends RSSurfaceView {
|
||||
public static final int STATE_COUNT = 8;
|
||||
public static final int STATE_TOUCH = 9;
|
||||
|
||||
|
||||
public RolloRS() {
|
||||
}
|
||||
|
||||
@@ -253,6 +252,7 @@ public class AllAppsView extends RSSurfaceView {
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
initNamed();
|
||||
initIcons(29);
|
||||
initRS();
|
||||
}
|
||||
|
||||
@@ -297,15 +297,15 @@ public class AllAppsView extends RSSurfaceView {
|
||||
private ProgramVertex.MatrixAllocation mPVAlloc;
|
||||
private ProgramVertex mPVOrtho;
|
||||
private ProgramVertex.MatrixAllocation mPVOrthoAlloc;
|
||||
private Allocation[] mIcons;
|
||||
private Allocation[] mLabels;
|
||||
|
||||
private int[] mAllocStateBuf;
|
||||
private Allocation mAllocState;
|
||||
|
||||
private Allocation[] mIcons;
|
||||
private int[] mAllocIconIDBuf;
|
||||
private Allocation mAllocIconID;
|
||||
|
||||
private Allocation[] mLabels;
|
||||
private int[] mAllocLabelIDBuf;
|
||||
private Allocation mAllocLabelID;
|
||||
|
||||
@@ -377,52 +377,48 @@ public class AllAppsView extends RSSurfaceView {
|
||||
mAllocScratch.data(mAllocScratchBuf);
|
||||
|
||||
Log.e("rs", "Done loading named");
|
||||
}
|
||||
|
||||
private void initIcons(int count) {
|
||||
mIcons = new Allocation[count];
|
||||
mAllocIconIDBuf = new int[count];
|
||||
mAllocIconID = Allocation.createSized(mRS,
|
||||
Element.USER_I32, mAllocIconIDBuf.length);
|
||||
|
||||
mLabels = new Allocation[count];
|
||||
mAllocLabelIDBuf = new int[mLabels.length];
|
||||
mAllocLabelID = Allocation.createSized(mRS,
|
||||
Element.USER_I32, mLabels.length);
|
||||
|
||||
Element ie8888 = Element.RGBA_8888;
|
||||
|
||||
{
|
||||
mIcons = new Allocation[29];
|
||||
mAllocIconIDBuf = new int[mIcons.length];
|
||||
mAllocIconID = Allocation.createSized(mRS,
|
||||
Element.USER_I32, mAllocIconIDBuf.length);
|
||||
final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
|
||||
|
||||
mLabels = new Allocation[29];
|
||||
mAllocLabelIDBuf = new int[mLabels.length];
|
||||
mAllocLabelID = Allocation.createSized(mRS,
|
||||
Element.USER_I32, mLabels.length);
|
||||
|
||||
Element ie8888 = Element.RGBA_8888;
|
||||
|
||||
for (int i=0; i<mIcons.length; i++) {
|
||||
mIcons[i] = Allocation.createFromBitmapResource(
|
||||
mRS, mRes, R.raw.maps, ie8888, true);
|
||||
mLabels[i] = makeTextBitmap("Maps");
|
||||
}
|
||||
|
||||
for(int ct=0; ct < mIcons.length; ct++) {
|
||||
mIcons[ct].uploadToTexture(0);
|
||||
mLabels[ct].uploadToTexture(0);
|
||||
mAllocIconIDBuf[ct] = mIcons[ct].getID();
|
||||
mAllocLabelIDBuf[ct] = mLabels[ct].getID();
|
||||
}
|
||||
mAllocIconID.data(mAllocIconIDBuf);
|
||||
mAllocLabelID.data(mAllocLabelIDBuf);
|
||||
for (int i=0; i<count; i++) {
|
||||
mIcons[i] = Allocation.createFromBitmapResource(
|
||||
mRS, mRes, R.raw.maps, ie8888, true);
|
||||
mLabels[i] = makeTextBitmap(bubble, i%9==0 ? "Google Maps" : "Maps");
|
||||
}
|
||||
|
||||
for(int ct=0; ct < count; ct++) {
|
||||
mIcons[ct].uploadToTexture(0);
|
||||
mLabels[ct].uploadToTexture(0);
|
||||
mAllocIconIDBuf[ct] = mIcons[ct].getID();
|
||||
mAllocLabelIDBuf[ct] = mLabels[ct].getID();
|
||||
}
|
||||
mAllocIconID.data(mAllocIconIDBuf);
|
||||
mAllocLabelID.data(mAllocLabelIDBuf);
|
||||
|
||||
Log.e("rs", "Done loading icons");
|
||||
}
|
||||
|
||||
Allocation makeTextBitmap(String t) {
|
||||
Bitmap b = Bitmap.createBitmap(128, 32, Bitmap.Config.ARGB_8888);
|
||||
Canvas c = new Canvas(b);
|
||||
Paint p = new Paint();
|
||||
p.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
p.setTextSize(20);
|
||||
p.setColor(0xffffffff);
|
||||
c.drawText(t, 2, 26, p);
|
||||
return Allocation.createFromBitmap(mRS, b, Element.RGBA_8888, true);
|
||||
Allocation makeTextBitmap(Utilities.BubbleText bubble, String label) {
|
||||
Bitmap b = bubble.createTextBitmap(label);
|
||||
Allocation a = Allocation.createFromBitmap(mRS, b, Element.RGBA_8888, true);
|
||||
b.recycle();
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
private void initRS() {
|
||||
ScriptC.Builder sb = new ScriptC.Builder(mRS);
|
||||
sb.setScript(mRes, R.raw.rollo);
|
||||
|
||||
@@ -31,9 +31,9 @@ import android.text.Layout;
|
||||
* too aggressive.
|
||||
*/
|
||||
public class BubbleTextView extends TextView {
|
||||
private static final float CORNER_RADIUS = 8.0f;
|
||||
private static final float PADDING_H = 5.0f;
|
||||
private static final float PADDING_V = 1.0f;
|
||||
static final float CORNER_RADIUS = 8.0f;
|
||||
static final float PADDING_H = 5.0f;
|
||||
static final float PADDING_V = 1.0f;
|
||||
|
||||
private final RectF mRect = new RectF();
|
||||
private Paint mPaint;
|
||||
|
||||
@@ -20,12 +20,18 @@ import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.PaintDrawable;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PaintFlagsDrawFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PaintFlagsDrawFilter;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.Layout.Alignment;
|
||||
import android.text.StaticLayout;
|
||||
import android.text.TextPaint;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.content.res.Resources;
|
||||
import android.content.Context;
|
||||
|
||||
@@ -201,4 +207,111 @@ final class Utilities {
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
static class BubbleText {
|
||||
private static final int MAX_LINES = 2;
|
||||
private TextPaint mTextPaint;
|
||||
private Paint mRectPaint;
|
||||
|
||||
private float mBubblePadding;
|
||||
private float mCornerRadius;
|
||||
private RectF mBubbleRect = new RectF();
|
||||
|
||||
private float mTextWidth;
|
||||
private int mLeading;
|
||||
private int mFirstLineY;
|
||||
private int mLineHeight;
|
||||
|
||||
private int mBitmapWidth;
|
||||
private int mBitmapHeight;
|
||||
|
||||
BubbleText(Context context) {
|
||||
final Resources resources = context.getResources();
|
||||
|
||||
final float scale = resources.getDisplayMetrics().density;
|
||||
|
||||
final float paddingLeft = 5.0f * scale;
|
||||
final float paddingRight = 5.0f * scale;
|
||||
final float cellWidth = resources.getDimension(R.dimen.workspace_cell_width);
|
||||
final float bubbleWidth = cellWidth - paddingLeft - paddingRight;
|
||||
mBubblePadding = 5.0f * scale;
|
||||
|
||||
RectF bubbleRect = mBubbleRect;
|
||||
bubbleRect.left = 0;
|
||||
bubbleRect.top = 0;
|
||||
bubbleRect.right = (int)(bubbleWidth+0.5f);
|
||||
|
||||
mCornerRadius = BubbleTextView.CORNER_RADIUS * scale;
|
||||
mTextWidth = bubbleWidth - mBubblePadding - mBubblePadding;
|
||||
|
||||
Paint rectPaint = mRectPaint = new Paint();
|
||||
rectPaint.setColor(0xff000000);
|
||||
|
||||
TextPaint textPaint = mTextPaint = new TextPaint();
|
||||
textPaint.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
textPaint.setTextSize(20);
|
||||
textPaint.setColor(0xffffffff);
|
||||
|
||||
float ascent = -textPaint.ascent();
|
||||
float descent = textPaint.descent();
|
||||
float leading = (ascent+descent) * 0.1f;
|
||||
mLeading = (int)(leading + 0.5f);
|
||||
mFirstLineY = (int)(leading + ascent + 0.5f);
|
||||
mLineHeight = (int)(leading + ascent + descent + 0.5f);
|
||||
|
||||
roundToPow2(64);
|
||||
mBitmapWidth = roundToPow2((int)(mBubbleRect.width() + 0.5f));
|
||||
mBitmapHeight = roundToPow2((int)((MAX_LINES * mLineHeight) + mLeading + 0.5f));
|
||||
|
||||
Log.d(Launcher.LOG_TAG, "mBitmapWidth=" + mBitmapWidth + " mBitmapHeight="
|
||||
+ mBitmapHeight + " w=" + ((int)(mBubbleRect.width() + 0.5f))
|
||||
+ " h=" + ((int)((MAX_LINES * mLineHeight) + mLeading + 0.5f)));
|
||||
}
|
||||
|
||||
/** You own the bitmap after this and you must call recycle on it. */
|
||||
Bitmap createTextBitmap(String text) {
|
||||
Bitmap b = Bitmap.createBitmap(mBitmapWidth, mBitmapHeight, Bitmap.Config.ARGB_8888);
|
||||
Canvas c = new Canvas(b);
|
||||
|
||||
StaticLayout layout = new StaticLayout(text, mTextPaint, (int)mTextWidth,
|
||||
Alignment.ALIGN_CENTER, 1, 0, true);
|
||||
int lineCount = layout.getLineCount();
|
||||
if (lineCount > MAX_LINES) {
|
||||
lineCount = MAX_LINES;
|
||||
}
|
||||
if (lineCount > 0) {
|
||||
RectF bubbleRect = mBubbleRect;
|
||||
bubbleRect.bottom = (int)((lineCount * mLineHeight) + mLeading + mLeading + 0.0f);
|
||||
c.drawRoundRect(bubbleRect, mCornerRadius, mCornerRadius, mRectPaint);
|
||||
Log.d(Launcher.LOG_TAG, "bubbleRect=" + bubbleRect);
|
||||
}
|
||||
for (int i=0; i<lineCount; i++) {
|
||||
int x = (int)((mBubbleRect.width() - layout.getLineMax(i)) / 2.0f);
|
||||
int y = mFirstLineY + (i * mLineHeight);
|
||||
c.drawText(text.substring(layout.getLineStart(i), layout.getLineEnd(i)),
|
||||
x, y, mTextPaint);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
/** Only works for positive numbers. */
|
||||
static int roundToPow2(int n) {
|
||||
int orig = n;
|
||||
n >>= 1;
|
||||
int mask = 0x8000000;
|
||||
while (mask != 0 && (n & mask) == 0) {
|
||||
mask >>= 1;
|
||||
}
|
||||
while (mask != 0) {
|
||||
n |= mask;
|
||||
mask >>= 1;
|
||||
}
|
||||
n += 1;
|
||||
if (n != orig) {
|
||||
n <<= 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user