仿htc布局

2024-02-13 09:58
文章标签 布局 htc

本文主要是介绍仿htc布局,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

//-------------------------lock_test.xml--------------------------------

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="330dip"
  android:orientation="vertical">
  <RelativeLayout
   android:layout_width="fill_parent"
   android:layout_height="420dip"
   android:layout_marginTop="-20dip"
   android:id="@+id/up"
   >
   <ImageView
       android:layout_marginTop="130dip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/image"
    android:background="@drawable/lockscreen">
   </ImageView>
   <TextView
    android:layout_marginTop="135dip"
    android:id="@+id/cmcc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    
    >
   </TextView>
   
   <!-- pictrue of unlock -->
   <LinearLayout
       android:id="@+id/linear"
    android:layout_marginTop="10dip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_below="@id/cmcc">
    <ImageView
     android:layout_marginTop="12dip"
     android:layout_width="17px"
     android:layout_height="17px"
     android:src="@drawable/icon_lock">
    </ImageView>
    <TextView
     android:id="@+id/havelock"
     android:layout_marginTop="5dip"
     android:layout_marginLeft="8dip"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_centerHorizontal="true"
     android:textSize="22dip"
     android:text="@string/havelock"
     >
    </TextView>
   </LinearLayout>
   <TextView
    android:id="@+id/time"
    android:layout_below="@id/cmcc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:textSize="45dip"
    android:layout_marginTop="3dip">
   </TextView>
   <TextView
    android:id="@+id/date"
    android:layout_marginTop="-1dip"
    android:layout_below="@id/time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:textStyle="bold"
    >
   </TextView>
   <!--第二行 -->
   <ImageView
   android:id="@+id/left"
    android:layout_marginLeft="40dip"
    android:layout_marginTop="10dip"
    android:layout_below="@id/image"
    android:layout_alignParentLeft="true"
    android:layout_width="18dip"
    android:layout_height="30dip"
    android:src="@drawable/arrseven">
   </ImageView>
   <TextView
    android:id="@+id/drag_info"
    android:layout_width="wrap_content"
    android:layout_below="@id/image"
    android:layout_marginTop="10dip"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="@string/drag_info"/>
   <ImageView
       android:id="@+id/right"
    android:layout_marginRight="40dip"
    android:layout_marginTop="10dip"
    android:layout_below="@id/image"
    android:layout_alignParentRight="true"
    android:layout_width="18dip"
    android:layout_height="30dip"
    android:src="@drawable/arreight"
    >
   </ImageView>
  </RelativeLayout>
 </LinearLayout>

 

//----------------------------------------SlidingTab.java---------------------------------------------------------

package com.android.internal.widget;

import com.android.internal.widget.SlidingTab_htc.OnTriggerListener;
import com.android.internal.R;
import android.content.Context;
import android.graphics.Color;
import android.os.Vibrator;
import android.util.AttributeSet;
import android.util.Log;

import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SlidingTab_htc extends LinearLayout {

RelativeLayout up;
 ImageView left, right,image;
 LinearLayout linear;
 TextView havelock, cmcc, time, date, drag_info,ampm;//add by xzg_006
 private float down_y = 0;
 private int deltaY = 0;
 private boolean mTracking = false;
 private static final long VIBRATE_SHORT = 30;
 private static final long VIBRATE_LONG = 40;
 private OnTriggerListener mOnTriggerListener;
 private int mGrabbedState = OnTriggerListener.NO_HANDLE;
 private boolean mTriggered = false;
 private Vibrator mVibrator;
 private static final int ANIM_DURATION = 350;
 private static final int start_y = 90;
 private static final int TARGET_LENGHT = 90;
 private  boolean ISCALLING = false;
 public SlidingTab_htc(Context context, AttributeSet attrs) {

  super(context, attrs);
  Log.i("xia", "SlidingTab_htc---SlidingTab_htc()");
  // TODO Auto-generated constructor stub
  final LayoutInflater inflater = LayoutInflater.from(context);
  inflater.inflate(R.layout.lock_test, this, true);
 }

//add by xzg_004 for bug_id null to htc_lockscreen phonenummber begin
 public void setCalling(String phonenummber){
  time.setVisibility(View.VISIBLE);
  time.setTextSize(24);
  time.setText(phonenummber);
 }
//add by xzg_004 for bug_id null to htc_lockscreen phonenummber end
 
 public void setCalling(boolean flag){

  ISCALLING = flag;
  if(flag){
   image.setBackgroundResource(R.drawable.lockscreen_phone);
   drag_info.setText(R.string.draginfo);
   cmcc.setVisibility(View.INVISIBLE);
   time.setVisibility(View.INVISIBLE);
   date.setVisibility(View.INVISIBLE);
   linear.setVisibility(View.INVISIBLE);
   drag_info.setVisibility(View.VISIBLE);
   left.setVisibility(View.VISIBLE);
   right.setVisibility(View.VISIBLE);
  }
 }
 
 @Override
 protected void onFinishInflate() {
  super.onFinishInflate();
  Log.i("xia", "SlidingTab_htc---onFinishInflate()");
  up = (RelativeLayout) this.findViewById(R.id.up);// whole
  linear = (LinearLayout) this.findViewById(R.id.linear);// lock info


  cmcc = (TextView) this.findViewById(R.id.cmcc);
  time = (TextView) this.findViewById(R.id.time);
  havelock = (TextView) this.findViewById(R.id.havelock);
  date = (TextView) this.findViewById(R.id.date);
  ampm = (TextView) this.findViewById(R.id.ampm);//add by xzg_006
  drag_info = (TextView) this.findViewById(R.id.drag_info);
  left = (ImageView) this.findViewById(R.id.left);
  image = (ImageView) this.findViewById(R.id.image);
  right = (ImageView) this.findViewById(R.id.right);

  cmcc.setTextColor(Color.WHITE);
  time.setTextColor(Color.WHITE);
  havelock.setTextColor(Color.WHITE);
  date.setTextColor(Color.WHITE);

  diplaytime(true);
 }

 public void settimedate(String timestr,String datestr){

  Log.i("xia","--SlidingTab_htc----settimedate---------");
  
// modified by xzg_006 begin  
  String stra[] = timestr.split(" ");
  Log.i("xia","------"+stra[0]);
  time.setText(stra[0]);
  date.setText(datestr);
  if(stra.length>=2)
  {
   Log.i("xia","------"+stra[1]);
   ampm.setText(stra[1]);
  }
  Log.i("xia","--settimedate end---");
 }
// modified by xzg_006 end  
 public void setCmcc(String timestr){
  cmcc.setText(timestr);  
 }
 
 public interface OnTriggerListener {

  public static final int NO_HANDLE = 0;

  public static final int LEFT_HANDLE = 1;

  public static final int RIGHT_HANDLE = 2;

  void onTrigger(View v, int whichHandle);

  void onGrabbedStateChange(View v, int grabbedState);
 }
 public void setRightTabResources(int iconId, int targetId, int barId,
   int tabId) {
  Log.i("xia", "SlidingTab_htc---setRightTabResources()");
 }

 public void setLeftHintText(int resId) {
  Log.i("xia", "SlidingTab_htc---setLeftHintText()");
 }

 public void setLeftTabResources(int iconId, int targetId, int barId,
   int tabId) {
  Log.i("xia", "SlidingTab_htc---setLeftTabResources()");
  // mLeftSlider.setIcon(iconId);
  // // mLeftSlider.setTarget(targetId);
  // mLeftSlider.setBarBackgroundResource(barId);
  // mLeftSlider.setTabBackgroundResource(tabId);
  // mLeftSlider.updateDrawableStates();
 }


 @Override
 public void setVisibility(int visibility) {
  Log.i("xia", "SlidingTab_htc---setVisibility(visibility)"+visibility);
  if(visibility==0)
  {
   deltaY = 0;
   up.setPadding(0, 0, 0, 0);
  }
  if (visibility != getVisibility() && visibility == View.INVISIBLE) {
   reset(false);
  }
  super.setVisibility(visibility);
 }

 public void resetViews() {
  up.setPadding(0, 0, 0, 0);
  
  diplaytime(true);
 }

 void diplaytime(boolean flag) {

  
  if(!ISCALLING){
  if (flag) {
   cmcc.setVisibility(View.VISIBLE);
   time.setVisibility(View.VISIBLE);
   date.setVisibility(View.VISIBLE);
   ampm.setVisibility(View.VISIBLE); //rgk_20111202_xzg_lockscreen_shangwu_kejian
   linear.setVisibility(View.INVISIBLE);
   drag_info.setVisibility(View.INVISIBLE);
   left.setVisibility(View.INVISIBLE);
   right.setVisibility(View.INVISIBLE);
  } else {
   cmcc.setVisibility(View.INVISIBLE);
   time.setVisibility(View.INVISIBLE);
   date.setVisibility(View.INVISIBLE);
   ampm.setVisibility(View.INVISIBLE); //rgk_20111202_xzg_lockscreen_shangwu_BUkejian
   linear.setVisibility(View.VISIBLE);
   drag_info.setVisibility(View.VISIBLE);
   left.setVisibility(View.VISIBLE);
   right.setVisibility(View.VISIBLE);
  }
  }
 }
 // public SlidingTab_htc(Context context, AttributeSet attrs) {
 // super(context, attrs);
 // }

 public void setDragInfo(String DragInfo){
  drag_info.setVisibility(View.VISIBLE);
  drag_info.setText(DragInfo);
 }
 
 @Override
 public boolean onInterceptTouchEvent(MotionEvent event) {
  Log.i("xia", " 33 onInterceptTouchEvent");
  final int action = event.getAction();
  final float x = event.getX();
  final float y = event.getY();
  Log.i("xia", " x = " + x + " y = " + y);
  // if (mAnimating) {
  // return false;
  // }
  // mLeftSlider.display_date(false);

  boolean leftHit = y > 0 && y < 250;

  Log.i("xia", " leftHit = " + leftHit);

  if (!mTracking && !leftHit) {
   Log.i("xia", "aaaaaaaaaaaa return fallse ");
   return false;
  }

  switch (action) {
  case MotionEvent.ACTION_DOWN: {
   Log.i("xia", "bbbbbbbbbbbb ACTION_DOWN ");
   down_y = y;
   diplaytime(false);
   mTracking = true;
   // mTriggered = false;
//    vibrate(VIBRATE_SHORT);

   // mCurrentSlider = mLeftSlider;
   // mThreshold = isHorizontal() ? THRESHOLD : 1.0f - THRESHOLD;
   // setGrabbedState(OnTriggerListener.LEFT_HANDLE);
   // mCurrentSlider.setState(Slider.STATE_PRESSED);
   break;
  }
  }

  return true;
 }

 @Override
 public boolean onTouchEvent(MotionEvent event) {
  if (mTracking) {
   final int action = event.getAction();
   final float y = event.getY();

   switch (action) {
   case MotionEvent.ACTION_MOVE:
    Log.i("xia", " 44 MotionEvent.ACTION_MOVE");
    if (y > 0 && y < 330) {
     moveHandle(y);
     break;
    }
   case MotionEvent.ACTION_UP:
   case MotionEvent.ACTION_CANCEL:
    Log.i("xia", " 44 MotionEvent.ACTION_CANCEL");
    
    if(!ISCALLING){
     boolean thresholdReached;
     thresholdReached = deltaY > 95;
     if (thresholdReached) {
      Log.i("xia", "====reset(true)=====");
      reset(true);

      dispatchTriggerEvent(OnTriggerListener.LEFT_HANDLE);
      setGrabbedState(OnTriggerListener.NO_HANDLE);
     } else {
      Log.i("xia", "====reset(false)=====");
      reset(false);
      setGrabbedState(OnTriggerListener.NO_HANDLE);
     }
    }else{
             if(deltaY > 90){
      reset(true);
      dispatchTriggerEvent(OnTriggerListener.LEFT_HANDLE);
      setGrabbedState(OnTriggerListener.NO_HANDLE);
     }else if(deltaY < -80){
      reset();
      dispatchTriggerEvent(OnTriggerListener.RIGHT_HANDLE);
      setGrabbedState(OnTriggerListener.NO_HANDLE);
     }else
     {
      reset(false);
      setGrabbedState(OnTriggerListener.NO_HANDLE);
     }
    }
    
    
    mTracking = false;
    break;
   }
  }


  return  mTracking || super.onTouchEvent(event);
 }

 public void reset(boolean flag) {
  if (deltaY != 0) {
   if (!flag) {
    Log.i("xia", " deltaY " + deltaY);
    up.setPadding(0, 0, 0, 0);
    TranslateAnimation trans = new TranslateAnimation(0, 0, deltaY,
      0);
    trans.setDuration(ANIM_DURATION);
    trans.setFillAfter(false);
    trans.setAnimationListener(mAnimationDoneListener);
    up.startAnimation(trans);
   } else {
    Log.i("xia", " deltaY " + deltaY);
    up.setPadding(0, deltaY + 50, 0, -(deltaY + 50));
    TranslateAnimation trans = new TranslateAnimation(0, 0, -50, 0);
    trans.setDuration(ANIM_DURATION);
    trans.setFillAfter(false);
    trans.setAnimationListener(mAnimationDoneListener);
    up.startAnimation(trans);
   }
  }
  deltaY = 0;
 }

 public void reset() {
    Log.i("xia", " deltaY " + deltaY);
//    up.setPadding(0, deltaY - 50, 0, -(deltaY - 50));
//    TranslateAnimation trans = new TranslateAnimation(0, 0, 50, 0);
//    trans.setDuration(ANIM_DURATION);
//    trans.setFillAfter(false);
//    trans.setAnimationListener(mAnimationDoneListener);
//    up.startAnimation(trans);
          deltaY = 0;
 }
 private void moveHandle(float y) {
  if (!ISCALLING) {
   if (y > down_y && y > start_y) {
    if (down_y < start_y) {
     deltaY = (int) (y - start_y);
    } else {
     deltaY = (int) (y - down_y);

    }
    up.setPadding(0, deltaY, 0, -(deltaY));
   }
  }
  else{
   deltaY = (int) (y - down_y);
   up.setPadding(0, deltaY, 0, -(deltaY));
  }

  // TODO: be more conservative about what we're invalidating
 }

 private final AnimationListener mAnimationDoneListener = new AnimationListener() {

  // @Override
  public void onAnimationEnd(Animation arg0) {
   // TODO Auto-generated method stub
   onAnimationDone();
  }

  // @Override
  public void onAnimationRepeat(Animation arg0) {
   // TODO Auto-generated method stub

  }

  // @Override
  public void onAnimationStart(Animation arg0) {
   // TODO Auto-generated method stub

  }
 };

 void onAnimationDone() {
  up.setPadding(0, 0, 0, 0);
  diplaytime(true);
 }

 public void setRightHintText(int resId) {
  Log.i("xia", "SlidingTab_htc---setRightHintText()");
 }

 public void setHoldAfterTrigger(boolean holdLeft, boolean holdRight) {
  Log.i("xia", "SlidingTab_htc---setHoldAfterTrigger()");
  // mHoldLeftOnTransition = holdLeft;
  // mHoldRightOnTransition = holdRight;
 }

 /**
  * Triggers haptic feedback.
  */
 private synchronized void vibrate(long duration) {
  if (mVibrator == null) {
   mVibrator = (android.os.Vibrator) getContext().getSystemService(
     Context.VIBRATOR_SERVICE);
  }
  mVibrator.vibrate(duration);
 }

 public void setOnTriggerListener(OnTriggerListener listener) {
  Log.i("xia", "SlidingTab_htc---setOnTriggerListener()");
  mOnTriggerListener = listener;
 }

 /**
  * Dispatches a trigger event to listener. Ignored if a listener is not set.
  *
  * @param whichHandle
  *            the handle that triggered the event.
  */
 private void dispatchTriggerEvent(int whichHandle) {
  Log.i("xia", "SlidingTab_htc---dispatchTriggerEvent(whichHandle=" + whichHandle + ")");// invork
                    // call
                    // lockscreen
                    // method
  vibrate(VIBRATE_LONG);
  if (mOnTriggerListener != null) {
   mOnTriggerListener.onTrigger(this, whichHandle);
  }
 }


 /**
  * Sets the current grabbed state, and dispatches a grabbed state change
  * event to our listener.
  */
 private void setGrabbedState(int newState) {
  Log.i("xia", "SlidingTab_htc---setGrabbedState(wint newState)");
  if (newState != mGrabbedState) {
   mGrabbedState = newState;
   if (mOnTriggerListener != null) {
    mOnTriggerListener.onGrabbedStateChange(this, mGrabbedState);
   }
  }
 }

}

 

这篇关于仿htc布局的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/705205

相关文章

CSS3 最强二维布局系统之Grid 网格布局

《CSS3最强二维布局系统之Grid网格布局》CS3的Grid网格布局是目前最强的二维布局系统,可以同时对列和行进行处理,将网页划分成一个个网格,可以任意组合不同的网格,做出各种各样的布局,本文介... 深入学习 css3 目前最强大的布局系统 Grid 网格布局Grid 网格布局的基本认识Grid 网

CSS弹性布局常用设置方式

《CSS弹性布局常用设置方式》文章总结了CSS布局与样式的常用属性和技巧,包括视口单位、弹性盒子布局、浮动元素、背景和边框样式、文本和阴影效果、溢出隐藏、定位以及背景渐变等,通过这些技巧,可以实现复杂... 一、单位元素vm 1vm 为视口的1%vh 视口高的1%vmin 参照长边vmax 参照长边re

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

lvgl8.3.6 控件垂直布局 label控件在image控件的下方显示

在使用 LVGL 8.3.6 创建一个垂直布局,其中 label 控件位于 image 控件下方,你可以使用 lv_obj_set_flex_flow 来设置布局为垂直,并确保 label 控件在 image 控件后添加。这里是如何步骤性地实现它的一个基本示例: 创建父容器:首先创建一个容器对象,该对象将作为布局的基础。设置容器为垂直布局:使用 lv_obj_set_flex_flow 设置容器

Apache Tiles 布局管理器

陈科肇 =========== 1.简介 一个免费的开源模板框架现代Java应用程序。  基于该复合图案它是建立以简化的用户界面的开发。 对于复杂的网站,它仍然最简单,最优雅的方式来一起工作的任何MVC技术。 Tiles允许作者定义页面片段可被组装成在运行一个完整的网页。  这些片段,或Tiles,可以用于为了降低公共页面元素的重复,简单地包括或嵌入在其它瓦片,制定了一系列可重复使用

【CSS in Depth 2 精译_023】第四章概述 + 4.1 Flexbox 布局的基本原理

当前内容所在位置(可进入专栏查看其他译好的章节内容) 第一章 层叠、优先级与继承(已完结) 1.1 层叠1.2 继承1.3 特殊值1.4 简写属性1.5 CSS 渐进式增强技术1.6 本章小结 第二章 相对单位(已完结) 2.1 相对单位的威力2.2 em 与 rem2.3 告别像素思维2.4 视口的相对单位2.5 无单位的数值与行高2.6 自定义属性2.7 本章小结 第三章 文档流与盒模型(已

ConstraintLayout布局里的一个属性app:layout_constraintDimensionRatio

ConstraintLayout 这是一个约束布局,可以尽可能的减少布局的嵌套。有一个属性特别好用,可以用来动态限制宽或者高app:layout_constraintDimensionRatio 关于app:layout_constraintDimensionRatio参数 app:layout_constraintDimensionRatio=“h,1:1” 表示高度height是动态变化

html记账本改写:数据重新布局,更好用了,没有localStorage保存版本

<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><title>htm记账本</title><style>table {user-select: none;/* width: 100%; */border-collapse: collapse;}table,th,td {border: 1px solid bla

Qt-常用控件(3)-多元素控件、容器类控件和布局管理器

1. 多元素控件 Qt 中提供的多元素控件有: QListWidgetQListViewQTableWidgetQTableViewQTreeWidgetQTreeView xxWidget 和 xxView 之间的区别,以 QTableWidget 和 QTableView 为例. QTableView 是基于 MVC 设计的控件.QTableView 自身不持有数据,使用 QTab