/*
* Copyright (C) 2010 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.
*/
package com.android.customlayout;
import android.app.Activity;
//import android.app.INotificationManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewDebug;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.View.OnLongClickListener;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
public class CustomLayout extends ViewGroup implements View.OnTouchListener, View.OnClickListener, OnLongClickListener
{
static final String TAG = "CustomLayout";
private int mWidthGap = 20;
private int mHeightGap = 20;
private int mCellWidth = 80;
private int mCellHeight = 120;
private float mRatio = 0;
private final int MAX_ITEM_NUM = 9;
private int[][] mLayout;
private final int[][] finalarray={{3,3,3},{3,3,3},{3,3,3},{3,3,3},{3,3,3},{3,3,3},{3,3,3},{3,3,3},{3,3,3}};
private int mItemCount = 0;
private int mSelectedPosition = 0;
private Activity mLauncher;
private CustomLayout.Animate mCustomAnimate = new CustomLayout.Animate();
private Rect[] mChildRects;
private static final Object ADD_BTN_TAG = new Object();
private WorkspaceQuickViewInfoProvider mWsQVProvider;
public CustomLayout(Context context) {
super(context);
mLauncher = (Activity) context;
setlayoutarray(finalarray,0);
}
public CustomLayout(Context context,AttributeSet attrs){
super(context, attrs);
mLauncher = (Activity) context;
setlayoutarray(finalarray,0);
}
public CustomLayout(Context context, int[][] layout,float ratio) {
super(context);
setlayoutarray(layout,ratio);
}
public void setlayoutarray(int[][] layout,float ratio){
mLayout = new int[layout.length][];
for(int i = 0; i < layout.length; i++){
mLayout[i] = new int[layout[i].length];
for(int j = 0; j < layout[i].length; j++){
mLayout[i][j] = layout[i][j];
}
}
mRatio = ratio;
requestLayout();
}
public void enableHardwareLayers() {
setLayerType(LAYER_TYPE_HARDWARE, null);
}
public View getChildAt(int x, int y) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
CustomLayout.LayoutParams lp = (CustomLayout.LayoutParams) child.getLayoutParams();
if ((lp.x <= x) && (x < lp.x + lp.width) &&
(lp.y <= y) && (y < lp.y + lp.height)) {
return child;
}
}
return null;
}
public int getLayoutMaxColumn(){
int distro_set = mItemCount-1;
int maxItemsPerColumn = -1;
if(distro_set < 0){
return 0;
}
for(int column = 0; column<mLayout[distro_set].length; column++){
if(mLayout[distro_set][column]>maxItemsPerColumn ){
maxItemsPerColumn = mLayout[distro_set][column];
}
}
return maxItemsPerColumn;
}
public int getLayoutMaxRow(){
int distro_set = mItemCount-1;
return distro_set>=0?mLayout[distro_set].length:0;
}
public void setUpGap(int width,int height,int widthGap,int heightGap){
mCellWidth = width;
mCellHeight = height;
mWidthGap = widthGap;
mHeightGap = heightGap;
}
public void setup(int position,CustomLayout.LayoutParams layoutParam){
int nWidth = getMeasuredWidth() - getPaddingRight() - getPaddingLeft();
int nHeight = getMeasuredHeight()- getPaddingTop() - getPaddingBottom()-85;
int maxRow = getLayoutMaxRow();
int maxColumn= getLayoutMaxColumn();
mCellWidth = (nWidth-mWidthGap*(maxColumn+1))/maxColumn;
mCellHeight = (nHeight - mHeightGap*(maxRow+1))/maxRow;
int bigWidth = (int)(mCellHeight*mRatio);
if(bigWidth > mCellWidth){
mCellHeight = (int)(mCellWidth/mRatio);
}else{
mCellWidth = bigWidth;
}
int pos = position+1;
int posX = 0;
int posY = 0;
if(mLayout.length >= mItemCount){
for(int i = 0;i<mLayout[mItemCount-1].length;i++){
if(pos - mLayout[mItemCount-1][i]>0){
pos = pos - mLayout[mItemCount-1][i];
posY++;
}else{
posX = pos-1;
break;
}
}
}
int nColumn = mLayout[mItemCount-1][posY];
int x = (nWidth - (nColumn*mCellWidth)-(nColumn-1)*mWidthGap)/2 + posX*(mCellWidth+mWidthGap);
int y = (nHeight - (maxRow*mCellHeight)-(maxRow-1)*mHeightGap)/2 + posY*(mCellHeight+mHeightGap);
layoutParam.setPos(x,y,mCellWidth,mCellHeight);
}
public void setupPos(int position,CustomLayout.LayoutParams layoutParam){
int pos = position+1;
int posX = 0;
int posY = 0;
if(mLayout.length >= mItemCount){
for(int i = 0;i<mLayout[mItemCount-1].length;i++){
if(pos - mLayout[mItemCount-1][i]>0){
pos = pos - mLayout[mItemCount-1][i];
posY++;
}else{
posX = pos-1;
break;
}
}
}
int nColumn = mLayout[mItemCount-1][posY];
int x = (getMeasuredWidth() - (nColumn*mCellWidth)-(nColumn-1)*mWidthGap)/2 + posX*(mCellWidth+mWidthGap);
int y = posY*mCellHeight+ (posY+1)*mHeightGap;
layoutParam.setPos(x,y,mCellWidth,mCellHeight);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
mItemCount = getChildCount();
for (int i = 0; i < mItemCount; i++) {
View child = getChildAt(i);
measureChild(child,i,mItemCount);
if(child != null ){
child.setOnClickListener(this);
child.setOnLongClickListener(this);
// child.setOnTouchListener(this);
}
}
setMeasuredDimension(widthSize, heightSize);
}
public void measureChild(View child,int position,int nitem) {
CustomLayout.LayoutParams layoutParam = (CustomLayout.LayoutParams) child.getLayoutParams();
if(layoutParam == null){
layoutParam = new CustomLayout.LayoutParams();
}
if(mRatio > 0.00001){
this.setup(position,layoutParam);
}else{
this.setupPos(position,layoutParam);
}
child.setLayoutParams(layoutParam);
int childWidthMeasureSpec = MeasureSpec.mak
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
CustomLayout.rar (54个子文件)
CustomLayout
AndroidManifest.xml 1KB
res
layout
screen_cell_layout.xml 777B
screen_editor.xml 713B
drawable-ldpi
drawable
model_set_btn_normal.png 1KB
hotseat_icon_delete.png 2KB
model_set_btn_select.png 2KB
homescreen_quick_view_add.png 3KB
test_pattern.png 307B
homescreen_blue_normal_holo.9.png 131B
preview_bg.9.png 3KB
page_edit_mark_as_home.xml 1KB
homescreen_blue_strong_holo.9.png 131B
drawable-mdpi
drawable-hdpi
drawable-xhdpi
values
strings.xml 136B
src
com
android
customlayout
AnimateEngine.java 2KB
MarkAsHomeButton.java 402B
UseCustomLyoutMain.java 1KB
CellInfo.java 279B
CustomLayout.java 27KB
bin
classes
com
android
customlayout
AnimateEngine$1.class 1KB
AnimateEngine.class 2KB
BuildConfig.class 357B
CustomLayout$WorkspaceQuickViewInfoProvider.class 468B
CustomLayout$LayoutParams.class 2KB
R.class 573B
R$layout.class 463B
CustomLayout$Animate.class 3KB
R$attr.class 358B
MarkAsHomeButton.class 668B
CustomLayout.class 19KB
R$id.class 548B
UseCustomLyoutMain.class 2KB
R$string.class 421B
CellInfo.class 499B
R$drawable.class 788B
CustomLayout$1.class 1KB
AndroidManifest.xml 1KB
res
drawable
model_set_btn_normal.png 1KB
hotseat_icon_delete.png 2KB
model_set_btn_select.png 2KB
homescreen_quick_view_add.png 1KB
test_pattern.png 206B
homescreen_blue_normal_holo.9.png 228B
preview_bg.9.png 412B
homescreen_blue_strong_holo.9.png 228B
classes.dex 26KB
com..android.customlayout.UseCustomLyoutMain.apk 29KB
resources.ap_ 13KB
.classpath 364B
assets
project.properties 563B
.settings
org.eclipse.jdt.core.prefs 629B
org.eclipse.ltk.core.refactoring.prefs 137B
.project 846B
gen
com
android
customlayout
R.java 2KB
BuildConfig.java 166B
共 54 条
- 1
w279287350
- 粉丝: 6
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页