summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2014-07-02 21:36:27 (GMT)
committerRajesh Yengisetty <rajesh@cyngn.com>2014-08-06 16:38:04 (GMT)
commit2ce97880ca19ee79f7bafec4c44fb1aa9dce7c9c (patch)
tree465a195379605f29a2961eac6277f29294e424f9
parent35adb26e56973506eab6b0140da573072ca06a34 (diff)
downloadandroid_packages_apps_Trebuchet-2ce97880ca19ee79f7bafec4c44fb1aa9dce7c9c.zip
android_packages_apps_Trebuchet-2ce97880ca19ee79f7bafec4c44fb1aa9dce7c9c.tar.gz
android_packages_apps_Trebuchet-2ce97880ca19ee79f7bafec4c44fb1aa9dce7c9c.tar.bz2
Trebuchet: Draw the dynamic grid image dynamically
This commits makes it possible to draw the image which previews the selected grid dynamically. Change-Id: I7c029f06110afdf1fe62145a079bba76166bb690
-rw-r--r--res/drawable/grid.pngbin1971 -> 0 bytes
-rw-r--r--res/drawable/grid_comfortable.pngbin1984 -> 0 bytes
-rw-r--r--res/drawable/grid_condensed.pngbin2033 -> 0 bytes
-rw-r--r--res/drawable/grid_cozy.pngbin2006 -> 0 bytes
-rw-r--r--res/layout/dynamic_grid_size_screen.xml4
-rw-r--r--res/values/colors.xml3
-rw-r--r--src/com/android/launcher3/DynamicGridSizeFragment.java225
7 files changed, 124 insertions, 108 deletions
diff --git a/res/drawable/grid.png b/res/drawable/grid.png
deleted file mode 100644
index 79fe901..0000000
--- a/res/drawable/grid.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable/grid_comfortable.png b/res/drawable/grid_comfortable.png
deleted file mode 100644
index 34e3ef2..0000000
--- a/res/drawable/grid_comfortable.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable/grid_condensed.png b/res/drawable/grid_condensed.png
deleted file mode 100644
index ebc9d4e..0000000
--- a/res/drawable/grid_condensed.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable/grid_cozy.png b/res/drawable/grid_cozy.png
deleted file mode 100644
index 929bcb5..0000000
--- a/res/drawable/grid_cozy.png
+++ /dev/null
Binary files differ
diff --git a/res/layout/dynamic_grid_size_screen.xml b/res/layout/dynamic_grid_size_screen.xml
index 38db4b0..5109e73 100644
--- a/res/layout/dynamic_grid_size_screen.xml
+++ b/res/layout/dynamic_grid_size_screen.xml
@@ -34,12 +34,12 @@
android:textSize="16sp" />
</LinearLayout>
- <ImageView
+ <view
+ class="com.android.launcher3.DynamicGridSizeFragment$GridSizeView"
android:id="@+id/dynamic_grid_size_image"
android:layout_width="@dimen/dynamic_grid_size_image_width"
android:layout_height="@dimen/dynamic_grid_size_image_height"
android:layout_gravity="center_horizontal"
- android:adjustViewBounds="true"
android:layout_marginBottom="@dimen/grid_padding"/>
<ListView
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 434cdf9..3ec8c73 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -43,4 +43,7 @@
<color name="settings_bg_header_color">#FFb2b0ab</color>
<color name="settings_bg_selected_color">#26000000</color>
<color name="settings_transition_selected_color">#50000000</color>
+
+ <color name="dynamic_grid_preview_background">#FFFFFFFF</color>
+ <color name="dynamic_grid_preview_foreground">#FF000000</color>
</resources>
diff --git a/src/com/android/launcher3/DynamicGridSizeFragment.java b/src/com/android/launcher3/DynamicGridSizeFragment.java
index 490335d..9ab1ad0 100644
--- a/src/com/android/launcher3/DynamicGridSizeFragment.java
+++ b/src/com/android/launcher3/DynamicGridSizeFragment.java
@@ -1,6 +1,23 @@
+/*
+ * Copyright (C) 2014 The CyanogenMod 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.
+ */
+
package com.android.launcher3;
import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.app.Dialog;
import android.app.Fragment;
@@ -8,12 +25,11 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
-import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
@@ -25,13 +41,18 @@ import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.NumberPicker;
import android.widget.TextView;
+
import com.android.launcher3.settings.SettingsProvider;
-public class DynamicGridSizeFragment extends Fragment implements NumberPicker.OnValueChangeListener, Dialog.OnDismissListener{
- public static final String DYNAMIC_GRID_SIZE_FRAGMENT = "dynamicGridSizeFragment";
+public class DynamicGridSizeFragment extends Fragment
+ implements NumberPicker.OnValueChangeListener, Dialog.OnDismissListener {
+ public static final String DYNAMIC_GRID_SIZE_FRAGMENT = "DynamicGridSizeFragment";
+
public static final int MIN_DYNAMIC_GRID_ROWS = 2;
public static final int MIN_DYNAMIC_GRID_COLUMNS = 3;
- ImageView mDynamicGridImage;
+
+ GridSizeView mDynamicGrid;
+
ListView mListView;
View mCurrentSelection;
GridSizeArrayAdapter mAdapter;
@@ -43,11 +64,9 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
int mCustomGridColumns = 0;
View.OnClickListener mSettingsItemListener = new View.OnClickListener() {
-
@Override
public void onClick(View v) {
- mCurrentSize = DeviceProfile.GridSize
- .getModeForValue((Integer) v.getTag());
+ mCurrentSize = DeviceProfile.GridSize.getModeForValue((Integer) v.getTag());
setCleared(mCurrentSelection);
setSelected(v);
@@ -60,16 +79,15 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
((GridSizeArrayAdapter) mListView.getAdapter()).notifyDataSetChanged();
mAdapter.notifyDataSetInvalidated();
- setCurrentImage();
+ updateGridMetrics();
}
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
+ Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dynamic_grid_size_screen, container, false);
- mDynamicGridImage = (ImageView) v.findViewById(R.id.dynamic_grid_size_image);
- mDynamicGridImage.setBackground(getResources().getDrawable(R.drawable.grid));
+ mDynamicGrid = (GridSizeView) v.findViewById(R.id.dynamic_grid_size_image);
LinearLayout titleLayout = (LinearLayout) v.findViewById(R.id.dynamic_grid_title);
titleLayout.setOnClickListener(new View.OnClickListener() {
@@ -83,11 +101,11 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
SettingsProvider.getIntCustomDefault(getActivity(),
SettingsProvider.SETTINGS_UI_DYNAMIC_GRID_SIZE, 0));
- setCurrentImage();
+ updateGridMetrics();
mListView = (ListView) v.findViewById(R.id.dynamic_grid_list);
Resources res = getResources();
- String [] values = {
+ String[] values = {
res.getString(R.string.grid_size_comfortable),
res.getString(R.string.grid_size_cozy),
res.getString(R.string.grid_size_condensed),
@@ -99,64 +117,16 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
return v;
}
- private void setCurrentImage() {
- Drawable d = null;
- boolean custom = false;
-
- switch (mCurrentSize) {
- case Comfortable:
- d = getResources().getDrawable(R.drawable.grid_comfortable);
- break;
- case Cozy:
- d = getResources().getDrawable(R.drawable.grid_cozy);
- break;
- case Condensed:
- d = getResources().getDrawable(R.drawable.grid_condensed);
- break;
- default:
-
- custom = true;
- break;
- }
-
- if (d != null && !custom) {
- mDynamicGridImage.setImageBitmap(null);
- mDynamicGridImage.setBackground(d);
- } else if (custom) {
- mDynamicGridImage.setBackground(null);
- mDynamicGridImage.setImageBitmap(writeOnDrawable(R.drawable.grid));
+ private void updateGridMetrics() {
+ if (mCurrentSize == DeviceProfile.GridSize.Custom) {
+ mDynamicGrid.setMetrics(mCustomGridRows, mCustomGridColumns);
+ } else {
+ DeviceProfile grid = getGrid();
+ mDynamicGrid.setMetrics(grid.numRowsBase + mCurrentSize.getValue(),
+ grid.numColumnsBase + mCurrentSize.getValue());
}
}
- public Bitmap writeOnDrawable(int drawableId){
- LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
-
- int rows = mCustomGridRows == 0 ? (int) grid.numRows : mCustomGridRows;
- int columns = mCustomGridColumns == 0 ? (int) grid.numColumns : mCustomGridColumns;
-
- String text = rows + " " + "\u00d7" + " " + columns;
-
- Bitmap bm = BitmapFactory.decodeResource(getResources(),
- drawableId).copy(Bitmap.Config.ARGB_8888, true);
-
- Paint paint = new Paint();
- paint.setStyle(Paint.Style.FILL);
- paint.setColor(Color.BLACK);
- int px = getResources().getDimensionPixelOffset(R.dimen.grid_custom_text);
- paint.setTextSize(px);
-
- Canvas canvas = new Canvas(bm);
-
- float canvasWidth = canvas.getWidth();
- float sentenceWidth = paint.measureText(text);
- float startPositionX = (canvasWidth - sentenceWidth) / 2;
-
- canvas.drawText(text, startPositionX, bm.getHeight()/2, paint);
-
- return bm;
- }
-
@Override
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
if (enter) {
@@ -167,21 +137,14 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
final View darkPanel = ((Launcher) getActivity()).getDarkPanel();
darkPanel.setVisibility(View.VISIBLE);
- ObjectAnimator anim2 = ObjectAnimator.ofFloat(
- darkPanel , "alpha", 0.0f, 0.3f);
+ ObjectAnimator anim2 = ObjectAnimator.ofFloat(darkPanel, "alpha", 0.0f, 0.3f);
anim2.start();
- anim.addListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator arg0) {}
+ anim.addListener(new AnimatorListenerAdapter() {
@Override
- public void onAnimationRepeat(Animator arg0) {}
- @Override
- public void onAnimationEnd(Animator arg0) {
+ public void onAnimationEnd (Animator animation) {
darkPanel.setVisibility(View.GONE);
}
- @Override
- public void onAnimationCancel(Animator arg0) {}
});
return anim;
@@ -208,23 +171,23 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
private void showNumberPicker() {
mDialog = new Dialog(getActivity());
- mDialog.setTitle(getResources().getString(R.string.preferences_interface_homescreen_custom));
+ mDialog.setTitle(getResources().getString(
+ R.string.preferences_interface_homescreen_custom));
mDialog.setContentView(R.layout.custom_grid_size_dialog);
- NumberPicker nPRows= (NumberPicker) mDialog.findViewById(R.id.custom_rows);
+ NumberPicker nPRows = (NumberPicker) mDialog.findViewById(R.id.custom_rows);
NumberPicker nPColumns = (NumberPicker) mDialog.findViewById(R.id.custom_columns);
- LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
-
+ DeviceProfile grid = getGrid();
int rows = grid.numRowsBase;
int columns = grid.numColumnsBase;
- if (mCustomGridColumns == 0) {
- mCustomGridColumns = (int) grid.numColumns;
- }
+
if (mCustomGridRows == 0) {
mCustomGridRows = (int) grid.numRows;
}
+ if (mCustomGridColumns == 0) {
+ mCustomGridColumns = (int) grid.numColumns;
+ }
nPRows.setMinValue(Math.max(MIN_DYNAMIC_GRID_ROWS, rows - DeviceProfile.GRID_SIZE_MIN));
nPRows.setMaxValue(rows + DeviceProfile.GRID_SIZE_MAX);
@@ -233,15 +196,16 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
nPRows.setOnValueChangedListener(this);
nPRows.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
- nPColumns.setMinValue(Math.max(MIN_DYNAMIC_GRID_COLUMNS, columns - DeviceProfile.GRID_SIZE_MIN));
+ nPColumns.setMinValue(Math.max(MIN_DYNAMIC_GRID_COLUMNS,
+ columns - DeviceProfile.GRID_SIZE_MIN));
nPColumns.setMaxValue(columns + DeviceProfile.GRID_SIZE_MAX);
nPColumns.setValue(mCustomGridColumns);
nPColumns.setWrapSelectorWheel(false);
nPColumns.setOnValueChangedListener(this);
nPColumns.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
- Button b = (Button) mDialog.findViewById(R.id.dialog_confirm_button);
- b.setOnClickListener(new View.OnClickListener() {
+ Button button = (Button) mDialog.findViewById(R.id.dialog_confirm_button);
+ button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mDialog != null) {
@@ -249,6 +213,7 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
}
}
});
+
mDialog.setOnDismissListener(this);
mDialog.show();
}
@@ -278,16 +243,14 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
SettingsProvider.SETTINGS_UI_HOMESCREEN_COLUMNS, mCustomGridColumns);
mAdapter.notifyDataSetInvalidated();
-
- setCurrentImage();
+ mDynamicGrid.setMetrics(mCustomGridRows, mCustomGridColumns);
}
private class GridSizeArrayAdapter extends ArrayAdapter<String> {
Context mContext;
String[] mTitles;
- public GridSizeArrayAdapter(Context context, int textViewResourceId,
- String[] objects) {
+ public GridSizeArrayAdapter(Context context, int textViewResourceId, String[] objects) {
super(context, textViewResourceId, objects);
mContext = context;
@@ -296,27 +259,29 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- LayoutInflater inflater = (LayoutInflater) mContext
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- convertView = inflater.inflate(R.layout.settings_pane_list_item,
- parent, false);
- TextView textView = (TextView) convertView
- .findViewById(R.id.item_name);
+ if (convertView == null) {
+ LayoutInflater inflater = (LayoutInflater)
+ mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ convertView = inflater.inflate(R.layout.settings_pane_list_item, parent, false);
+ }
+
+ TextView textView = (TextView) convertView.findViewById(R.id.item_name);
textView.setText(mTitles[position]);
- // Set Selected State
+
+ // Set selected state
if (position == mCurrentSize.getValue()) {
+ if (mCurrentSelection != null) {
+ setCleared(mCurrentSelection);
+ }
mCurrentSelection = convertView;
setSelected(mCurrentSelection);
}
if (position == DeviceProfile.GridSize.Custom.getValue()) {
- LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
-
int rows = SettingsProvider.getIntCustomDefault(getActivity(),
- SettingsProvider.SETTINGS_UI_HOMESCREEN_ROWS, grid.numRowsBase);
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_ROWS, getGrid().numRowsBase);
int columns = SettingsProvider.getIntCustomDefault(getActivity(),
- SettingsProvider.SETTINGS_UI_HOMESCREEN_COLUMNS, grid.numColumnsBase);
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_COLUMNS, getGrid().numColumnsBase);
String gridSize = rows + " " + "\u00d7" + " " + columns;
textView.setText(getString(R.string.grid_size_custom_and_size, gridSize));
@@ -327,4 +292,52 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
return convertView;
}
}
+
+ private DeviceProfile getGrid() {
+ LauncherAppState app = LauncherAppState.getInstance();
+ return app.getDynamicGrid().getDeviceProfile();
+ }
+
+ private static class GridSizeView extends View {
+ private int mRows = 0, mColumns = 0;
+ private Paint mForegroundPaint;
+ private int mBackgroundColor;
+
+ public GridSizeView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ Resources res = context.getResources();
+
+ mForegroundPaint = new Paint();
+ mForegroundPaint.setColor(res.getColor(R.color.dynamic_grid_preview_foreground));
+ mBackgroundColor = res.getColor(R.color.dynamic_grid_preview_background);
+ }
+
+ public void setMetrics(int rows, int columns) {
+ mRows = rows;
+ mColumns = columns;
+ invalidate();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ float width = getWidth() - getPaddingLeft() - getPaddingRight();
+ float height = getHeight() - getPaddingTop() - getPaddingBottom();
+ float xOffset = getPaddingLeft();
+ float yOffset = getPaddingTop();
+
+ canvas.drawColor(mBackgroundColor);
+
+ // Draw rows
+ for (int i = 1; i < mRows; i++) {
+ float yPos = yOffset + height / mRows * i;
+ canvas.drawLine(xOffset, yPos, xOffset + width, yPos, mForegroundPaint);
+ }
+
+ // Draw columns
+ for (int j = 1; j < mColumns; j++) {
+ float xPos = xOffset + width / mColumns * j;
+ canvas.drawLine(xPos, yOffset, xPos, yOffset + height, mForegroundPaint);
+ }
+ }
+ }
}