summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2014-07-02 23:36:27 +0200
committerAdnan Begovic <adnan@cyngn.com>2014-11-23 23:12:22 +0000
commit90ae307eedcb2f90d4cdcb0276018b6e0e92c304 (patch)
tree54a872f05cf4236a0a7c7eb0f028b4b24a8da976
parent465fa647ba06b8d76c79ce044a18a47ebe212e86 (diff)
downloadandroid_packages_apps_Trebuchet-90ae307eedcb2f90d4cdcb0276018b6e0e92c304.tar.gz
android_packages_apps_Trebuchet-90ae307eedcb2f90d4cdcb0276018b6e0e92c304.tar.bz2
android_packages_apps_Trebuchet-90ae307eedcb2f90d4cdcb0276018b6e0e92c304.zip
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/cm_strings.xml4
-rw-r--r--res/values/colors.xml3
-rw-r--r--src/com/android/launcher3/DynamicGridSizeFragment.java271
8 files changed, 154 insertions, 128 deletions
diff --git a/res/drawable/grid.png b/res/drawable/grid.png
deleted file mode 100644
index 79fe901d1..000000000
--- 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 34e3ef2ee..000000000
--- 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 ebc9d4e54..000000000
--- 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 929bcb541..000000000
--- 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 984f24a0f..8b6ed95ca 100644
--- a/res/layout/dynamic_grid_size_screen.xml
+++ b/res/layout/dynamic_grid_size_screen.xml
@@ -35,12 +35,12 @@
android:textSize="16sp" />
</LinearLayout>
- <ImageView
+ <view
+ class="com.android.launcher3.DynamicGridSizeFragment$GridSizeView"
android:id="@+id/dynamic_grid_size_image"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
- android:adjustViewBounds="true"
android:layout_marginBottom="@dimen/grid_padding"/>
<ListView
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index be2d91928..f724a5f5a 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<resources>
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Application name -->
<string name="cm_application_name" translatable="false">Trebuchet</string>
<!-- App version -->
@@ -68,7 +68,7 @@
<string name="grid_size_comfortable">Comfortable</string>
<string name="grid_size_cozy">Cozy</string>
<string name="grid_size_condensed">Condensed</string>
- <string name="grid_size_custom">Custom</string>
+ <string name="grid_size_custom">Custom (<xliff:g id="rows">%1$d</xliff:g> \u00d7 <xliff:g id="columns">%2$d</xliff:g>)</string>
<string name="preferences_interface_homescreen_custom">Select custom size</string>
<string name="preferences_interface_homescreen_rows_title">Number of rows</string>
<string name="preferences_interface_homescreen_columns_title">Number of columns</string>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index fd50ffd73..948801f5b 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -46,4 +46,7 @@
<color name="settings_transition_selected_color">#50000000</color>
<color name="infomation_count_circle_color">#F44336</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 f8ada16f6..55d2bf0cf 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;
@@ -9,34 +26,38 @@ import android.content.DialogInterface;
import android.content.res.Configuration;
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.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
+import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
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;
+ GridSizeAdapter mAdapter;
DeviceProfile.GridSize mCurrentSize;
Dialog mDialog;
@@ -45,11 +66,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);
@@ -59,19 +78,18 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
showNumberPicker();
}
- ((GridSizeArrayAdapter) mListView.getAdapter()).notifyDataSetChanged();
+ ((GridSizeAdapter) 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() {
@@ -85,17 +103,21 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
SettingsProvider.getIntCustomDefault(getActivity(),
SettingsProvider.SETTINGS_UI_DYNAMIC_GRID_SIZE, 0));
- setCurrentImage();
+ DeviceProfile grid = getGrid();
+ mCustomGridRows = (int) grid.numRows;
+ mCustomGridColumns = (int) grid.numColumns;
+
+ updateGridMetrics();
mListView = (ListView) v.findViewById(R.id.dynamic_grid_list);
Resources res = getResources();
- String [] values = {
- res.getString(R.string.grid_size_comfortable),
- res.getString(R.string.grid_size_cozy),
- res.getString(R.string.grid_size_condensed),
- res.getString(R.string.grid_size_custom)};
- mAdapter = new GridSizeArrayAdapter(getActivity(),
- R.layout.settings_pane_list_item, values);
+ int[] valueResIds = {
+ R.string.grid_size_comfortable,
+ R.string.grid_size_cozy,
+ R.string.grid_size_condensed,
+ R.string.grid_size_custom
+ };
+ mAdapter = new GridSizeAdapter(getActivity(), valueResIds);
mListView.setAdapter(mAdapter);
// RTL
@@ -108,64 +130,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) {
@@ -182,21 +156,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;
@@ -223,23 +190,16 @@ 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;
- }
nPRows.setMinValue(Math.max(MIN_DYNAMIC_GRID_ROWS, rows - DeviceProfile.GRID_SIZE_MIN));
nPRows.setMaxValue(rows + DeviceProfile.GRID_SIZE_MAX);
@@ -248,15 +208,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) {
@@ -264,6 +225,7 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
}
}
});
+
mDialog.setOnDismissListener(this);
mDialog.show();
}
@@ -293,31 +255,42 @@ 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> {
+ private class GridSizeAdapter extends BaseAdapter {
Context mContext;
- String[] mTitles;
-
- public GridSizeArrayAdapter(Context context, int textViewResourceId,
- String[] objects) {
- super(context, textViewResourceId, objects);
+ int[] mTitleResIds;
+ public GridSizeAdapter(Context context, int[] resIds) {
mContext = context;
- mTitles = objects;
+ mTitleResIds = resIds;
+ }
+
+ @Override
+ public int getCount() {
+ return mTitleResIds.length;
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mContext.getString(mTitleResIds[position]);
}
@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);
- textView.setText(mTitles[position]);
+ 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);
// RTL
Configuration config = getResources().getConfiguration();
@@ -327,6 +300,9 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
// Set selected state
if (position == mCurrentSize.getValue()) {
+ if (mCurrentSelection != null) {
+ setCleared(mCurrentSelection);
+ }
mCurrentSelection = convertView;
setSelected(mCurrentSelection);
}
@@ -335,14 +311,13 @@ public class DynamicGridSizeFragment extends Fragment implements NumberPicker.On
LauncherAppState app = LauncherAppState.getInstance();
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
- String state = mTitles[position];
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);
- state += " " + "(" + rows + " " + "\u00d7" + " " + columns + ")";
-
- textView.setText(state);
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_COLUMNS, getGrid().numColumnsBase);
+ textView.setText(mContext.getString(mTitleResIds[position], rows, columns));
+ } else {
+ textView.setText(mTitleResIds[position]);
}
convertView.setOnClickListener(mSettingsItemListener);
@@ -350,4 +325,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);
+ }
+ }
+ }
}