《Android Launcherchrome扩展及应用开发发》怎么样

Android(9)
可能大家做Android机顶盒或者Android电视开发的比较少,这类开发基本上都是基于源码的开发,大家有一个git版本库,大家开发完了编译出来一个版本烧到板子上跑,要编译肯定就要编译环境什么的,google推荐的是在Ubuntu系统上搭建开发和编译环境。
首先要做的事情是环境搭建:
大家可以装双系统或者用Oracle VM VirtualBox在Windows上安装Ubuntu。安装双系统我这里就不说了,大家可以去网上查一下,这里有一个链接大家可以参考:。
在Windows环境下通过Oracle VM VirtualBox安装Ubuntu请参考:。
我这说一下注意事项:
(1).必须是Windows7,如果是Windows8可能会出现意想不到的事情,总之就是不想遇到麻烦就用Windows7。
(2).分配虚拟磁盘空间的时候至少要分配30G,因为你要下载android-sdk就会用上十几G,你要是再下载源码那你至少要分60G的空间。
(3).安装完系统后一定要安装增强插件,否则窗口无法全屏,安装方法如下图:
点击红色箭头所指位置,然后在弹出框输入用户密码确认安装,安装完毕重启就可以全屏了。配置开发环境:
(1).配置adb:
去官网下载android-sdk-linux,下载地址是:/android/ + 不同版本的sdk
例如:下载r20版本
r20的linux版本:/android/android-sdk_r20-linux.tgz
r20的windows版本:/android/android-sdk_r20-windows.zip
r20的mac版本:/android/android-sdk_r20-macosx.zip
把上面下载的sdk解压到一个目录,比如说是~/software/目录,
终端执行:sudo gedit ~/.bashrc &
在最后添加如下内容:
#set path for android sdk tools
exportPATH=$PATH:/home/leo/software/android-sdk-linux/tools
export PATH=$PATH:/home/wuhao/software/android-sdk-linux/platform-tools/
(2).配置java环境:
去官网:下载对应版本的jdk,我的是64位系统,所以下载:jdk-7u75-linux-x64.tar.gz
sudo mkdir&&/usr/lib/jvm/
cd /usr/lib/jvm/
cp &~/software/jdk-7u75-linux-x64.tar.gz & ./ & & &
sudo tar -vxzf &jdk-7u75-linux-x64.tar.gz
把环境变量配置在用户目录.bashrc文件中是最好的选择,在bashrc里添加:
sudo gedit ~/.bashrc
#set java environment
#JAVA_HOME=/usr/lib/jvm/jdk1.7.0_75
export JRE_HOME=/usr/lib/jvm/jdk1.7.0_75/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
重启生效或者source .bashrc生效
(3).剩下的就是IDE下载和配置了,你可以选用Eclipse或者Android Studio。
Launcher设计
在电视或者机顶盒上做UI开发,首先要考虑电视尺寸都比较大,你的UI展现要能够在电视屏幕上看着大小合适,展现的简洁舒服,别像原生Launcher那样好多小图标看着密密麻麻的,第二个是要方便遥控器操作,焦点导航显示正确,因为你不可能给机顶盒外接一个鼠标模仿触摸操作,那样太不方便。所以大家都会想到类似Windows 8的那种风格。设计大概像是下面的图:
产品要求:
(1)在显示第一屏的时候第二屏要在屏幕右侧有一部分显示,并且是缩小显示,在page二显示的时候page一在左侧缩小显示一部分,page三部分显示,page之间切换流畅,图标放大缩小流畅。
(2)在每一个图标上焦点的时候要放大显示,图标周围有阴影或者焦点框之类的突出显示出来,丢焦点的时候还原为正常显示。
(3)图标对应的应用链接可以在xml文件配置。
(4)page个数可以配置,可以通过简单的修改参数去掉某个page。
拿到上面的产品需求你会怎么做呢?我是作如下考虑的:
(1)第一个需求我想到了ViewPager、viewflipper,这两个可以做到page之间切换流畅。
(2)每一个图标抽象出来做成一个View,放大缩小用属性动画可以做到,对应的View xml文件可以自定义属性完成应用链接配置。
(3)灵活添加,删除page需要好好考虑一下代码实现。
哎呀,好累,一个周六几个小时就这么过去了,套用《框框日记》里面框框经常说的一句话“多么有意义的一天呀!”。
以上就是我Launcher&Metro风格实现的第一篇博文,简单描述了环境配置和设计思路,写的有不足之处还请各位多多包涵和交流,具体代码实现我会在我的下一篇博文中进行讲解,请多多关注!
第一时间获得博客更新提醒,以及更多技术信息分享,欢迎关注个人微信公众平台:程序员互动联盟(coder_online),扫一扫下方二维码或搜索微信号coder_online即可关注,我们可以在线交流。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:184167次
积分:2288
积分:2288
排名:第16999名
原创:58篇
转载:47篇
译文:13篇
评论:19条
欢迎关注:coder_online或程序员互动联盟
专业、及时、互动、分享,这里是程序员梦想的家
(3)(1)(3)(5)(4)(10)(32)(32)(1)(1)(1)(3)(2)(4)(16)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'Android 如何判断一个应用在运行&在一个应用中,或一个Service 、Receiver中判断一个应用是否正在运行,以便进行一些相关的处理。这个时候我们需要得到一个ActivityManager,这个Manager顾名思意就是管理Activity的,它有一个方法叫getRunningTasks,可以得到当前系统正在运行的Task的列表,代码如下:& & ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);& & List&RunningTaskInfo& list = am.getRunningTasks(100);& & for (RunningTaskInfo info : list) {& & & & if (info.topActivity.getPackageName().equals(MY_PKG_NAME) && info.baseActivity.getPackageName().equals(MY_PKG_NAME)) {& & & & & & isAppRunning =& & & & & & //find it, break& & & & & && & & & }& & }100表示取的最大的任务数,info.topActivity表示当前正在运行的Activity,info.baseActivity表系统后台有此进程在运行,具体要做如何判断就看自已的业务需求。这个类还有更多的方法可以取得系统运行的服务、内存使用情况等的方法,请各位自行查找。有一点要注意,如果想正常运行此方法,请在你的 AndroidManifest.xml 中加入:&uses-permission android:name="android.permission.GET_TASKS" /&否则可能会有exception抛出。=====================================//判断应用是否在运行&ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);List&RunningTaskInfo& list = am.getRunningTasks(100);boolean isAppRunning =String MY_PKG_NAME = "com.cyberblue.iitag";for (RunningTaskInfo info : list) { if (info.topActivity.getPackageName().equals(MY_PKG_NAME) || info.baseActivity.getPackageName().equals(MY_PKG_NAME)) {
isAppRunning =
Log.i(TAG,info.topActivity.getPackageName() + " info.baseActivity.getPackageName()="+info.baseActivity.getPackageName());
}}//运行中才去重启蓝牙,否则会导致安装了这个应用后蓝牙无法关闭if(isAppRunning){ BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()) {
// enable()打开蓝牙,这个方法打开蓝牙不会弹出提示
mBluetoothAdapter.enable(); }}================================================Android系统内部状态信息的相关api:得到ActivityManager :ActivityManager activityManager = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE)这个位查到底是什么信息: &&ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); &获取进程内存状态的信息:Debug.MemoryInfo[] processMemoryInfo = activityManager.getProcessMemoryInfo(processIds);&&获取当前运行的service信息:List&RunningServiceInfo& runningServiceInfos = activityManager.getRunningServices(MaxValue); &&获取当前运行的任务信息:List&RunningTaskInfo& runningTaskInfos = activityManager.getRunningTasks(MaxValue);其中runningTaskInfos 的 topActivity就是当前Task的活跃Activity在getRunningTasks()所返回的Task队列中系统会根据这些Task的活跃度有一个排序,越活跃越是靠前。第一个就是当前活动的Task/*** 检测某ActivityUpdate是否在当前Task的栈顶*/public boolean isTopActivy(String cmdName){& & & & ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);& & & & List&RunningTaskInfo& runningTaskInfos = manager.getRunningTasks(1);& & & & String cmpNameTemp =& & & & if(null != runningTaskInfos){& & & & & & & & cmpNameTemp=(runningTaskInfos.get(0).topActivity).toString);& & & & & & & & Log.e("cmpname","cmpname:"+cmpName);& & & & }& & & &if(null == cmpNameTemp)& & & &return cmpNameTemp.equals(cmdName);}最后在应用中添加所需的权限:&uses-permission android:name="android.permission.GET_TASKS"/&[java] view plaincopy&/**get the launcher status */ && & private &boolean isLauncherRunnig(Context context) { && & & & & & boolean result = && & & & & & List&String& names = getAllTheLauncher(); && & & & & & ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE) ; && & & & & & List&ActivityManager.RunningAppProcessInfo& appList = mActivityManager.getRunningAppProcesses() ; && & & & & & for (RunningAppProcessInfo running : appList) { && & & & & & & & & & if (running.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { && & & & & & & & & & & & & & for (int i = 0; i & names.size(); i++) { && & & & & & & & & & & & & & & & & & if (names.get(i).equals(running.processName)) { && & & & & & & & & & & & & & & & & & & & & & result = && & & & & & & & & & & & & & & & & & & & & & && & & & & & & & & & & & & & & & & & } && & & & & & & & & & & & & & } && & & & & & & & & & } && & & & & & } && & & & & & && & } &[java] view plaincopy&private List&String& getAllTheLauncher(){ && & & & List&String& names = && & & & PackageManager pkgMgt = this.getPackageManager(); && & & & Intent it = new Intent(Intent.ACTION_MAIN); & &&& & & & it.addCategory(Intent.CATEGORY_HOME); &&& & & & List&ResolveInfo& ra =pkgMgt.queryIntentActivities(it,0); &&& & & & if(ra.size() != 0){ && & & & & & names = new ArrayList&String&(); && & & & } && & & & for(int i=0;i& ra.size();i++) & & && & & & { && & & & String packageName = &ra.get(i).activityInfo.packageN && & & & names.add(packageName); && & & & } & && & & & && & } &android 取当前显示的activity是什么ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);ComponentName cn = am.getRunningTasks(1).get(0).topALog.d("", "pkg:"+cn.getPackageName());Log.d("", "cls:"+cn.getClassName());android 如何判断程序是否在前台运行[java] view plaincopy&private boolean isTopActivity(){ && & & & List&RunningTaskInfo& &tasksInfo = activityManager.getRunningTasks(1); && & & & if(tasksInfo.size() & 0){ && & & & & & //应用程序位于堆栈的顶层 && & & & & & if(packageName.equals(tasksInfo.get(0).topActivity.getPackageName())){ && & & & & & & & && & & & & & } && & & & } && & & & && & } &
阅读(...) 评论()android Launcher应用开发
有谁做过launcher方面应用的开发吗?如何实现类似小米的三个手指触控显示的缩略图,并且能够实现拖动换位的效果,整个流程如何实现?求高手指点啊~6020人阅读
今天主要是分析一下Launcher里面的所有应用列表。Android4.0 Launcher的所有应用列表跟2.X比较大的区别就是多了Widget的显示。下面会详细分析Launcher里面有关所有应用列表配置和代码分析。
1、AllApp列表配置文件
配置AllAPP应用列表界面的配置文件是\res\Layout\apps_customize_pane.xml文件。AllAPP列表使用了一个TabHost组织了两个页面(全部应用和Widget),通过界面上面的TabHost进行切换。下面是TabHost的配置和AllAPP界面配置,我这里需要把Widget部分功能取消,因为我做的Launcher把Widget放到workspace里面实现了。
//Edited by mythou//
&!-- 取消TabHost的显示,把TabHost设置为0dp高,避免影响all app显示 mythou --&
&com.android.launcher2.AppsCustomizeTabHost
android:background=&@android:color/transparent&&
&LinearLayout
android:id=&@+id/apps_customize_content&
android:orientation=&vertical&
android:layout_width=&match_parent&
android:layout_height=&match_parent&&
&!-- TabHost栏,配置TahHost栏的高度宽度        我这里把TabHost取消了,因为我的Launcher需要把Widget反正workspace里面实现,        所以全部应用列表修改成和2.X的Launcher一样 mythou--&
&FrameLayout
android:id=&@+id/tabs_container&
android:layout_width=&0dp&
android:layout_height=&0dp&
android:layout_marginTop=&0dp&
android:layout_gravity=&center_horizontal&&       &!-- TabHost上面Widget 的按钮--&
&com.android.launcher2.FocusOnlyTabWidget
android:id=&@android:id/tabs&
android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:layout_gravity=&left&
android:background=&@android:color/transparent&
android:tabStripEnabled=&false&
android:tabStripLeft=&@null&
android:tabStripRight=&@null&
android:divider=&@null& /&       &!--TabHost 右边的Android市场的图标,不需要可以去掉--&
android:id=&@+id/market_button&
layout=&@layout/market_button&
android:layout_width=&wrap_content&
android:layout_height=&match_parent&
android:layout_gravity=&right& /&
&/FrameLayout&
     &!--下面这里就是我们所有应用列表的选项和所有应用列表的显示View         需要注意的是AppsCustomizePagedView同时支持显示所有应用列表和Widget列表 mythou--&
&FrameLayout
android:id=&@android:id/tabcontent&
android:layout_width=&match_parent&
android:layout_height=&match_parent&
&       &!-- 所有应用列表是通过自定义VIewAppsCustomizePagedView显示,后面会详细分析这个View          下面只对部分重要属性加入注释--&
&com.android.launcher2.AppsCustomizePagedView
android:id=&@+id/apps_customize_pane_content&
android:layout_width=&match_parent&
android:layout_height=&match_parent&         //MaxAppCellCountX 和MaxAppCellCounY指的是所有App图标排列的最大行列数。         //一般设置为-1,表示无限制
launcher:maxAppCellCountX=&@integer/apps_customize_maxCellCountX&
launcher:maxAppCellCountY=&@integer/apps_customize_maxCellCountY&         //pageLayoutWidthGap和pageLayoutHeightGap分别表示菜单界面与屏幕边缘的距离,         //一般小屏幕这里设置为-1。避免边框太窄误触屏幕才需要设置。
launcher:pageLayoutWidthGap=&@dimen/apps_customize_pageLayoutWidthGap&
launcher:pageLayoutHeightGap=&@dimen/apps_customize_pageLayoutHeightGap&
launcher:pageLayoutPaddingTop=&50dp&         //pageLayoutPaddingXXX指的是内填充,这个和系统的padding一样
launcher:pageLayoutPaddingBottom=&@dimen/apps_customize_pageLayoutPaddingBottom&
launcher:pageLayoutPaddingLeft=&@dimen/apps_customize_pageLayoutPaddingLeft&
launcher:pageLayoutPaddingRight=&@dimen/apps_customize_pageLayoutPaddingRight&         //widgetCellWithGap和widgetCellHeightGap指的是widget列表界面各个widget之间的间隔,         //和系统的margin属性类似
launcher:widgetCellWidthGap=&@dimen/apps_customize_widget_cell_width_gap&
launcher:widgetCellHeightGap=&@dimen/apps_customize_widget_cell_height_gap&         //widgetCountX和WidgetCountY都是表示Widget界面每行每列显示多少Widget
launcher:widgetCountX=&@integer/apps_customize_widget_cell_count_x&
launcher:widgetCountY=&@integer/apps_customize_widget_cell_count_y&         //提示界面的焦点
launcher:clingFocusedX=&@integer/apps_customize_cling_focused_x&
launcher:clingFocusedY=&@integer/apps_customize_cling_focused_y&
launcher:maxGap=&@dimen/workspace_max_gap& /&       &!-- 加载全部应用时的旋转动画 --&
&FrameLayout
android:id=&@+id/animation_buffer&
android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:background=&#FF000000&
android:visibility=&gone& /&
       &!-- 分页符,代表多少页和当前页面--&
android:id=&@+id/paged_view_indicator&
layout=&@layout/scroll_indicator&
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:layout_gravity=&bottom& /&
&/FrameLayout&
&/LinearLayout&
  &!--第一次进入所有应用列表的提示界面,和workspace提示界面一样--&
&include layout=&@layout/all_apps_cling&
android:id=&@+id/all_apps_cling&
android:layout_width=&match_parent&
android:layout_height=&match_parent&/&
&/com.android.launcher2.AppsCustomizeTabHost&
& 上面已经针对TabHost的配置文件给了详细注释,这里需要说明的一点是,不管是所有应用列表还是Widget列表都是通过AppsCustomizedPagedView显示出来,也就是说这个自定义View支持两种形式显示。下面我们先对AppsCustomizeTabHost做个简单分析。
2、AppsCustomizeTabHost分析
AppsCustomizeTabHost是继承了TabHost的之类,主要是对TabHost进行扩展,增加一些功能。AppsCustomizeTabHost的代码不多,这里主要对生成AllAPP和Widget页面选项部分介绍一下。
//Edited by mythou//
protected void onFinishInflate()
//.......//创建所有应用列表Tab mythou
TextView tabV
label = mContext.getString(R.string.all_apps_button_label);
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(label);
tabView.setContentDescription(label);
addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
//Widget的Tab页面
label = mContext.getString(R.string.widgets_tab_label);
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(label);
tabView.setContentDescription(label);
addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
//设置监听器
setOnTabChangedListener(this);
AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
lastTab.setOnKeyListener(keyListener);
//Android商店按钮
View shopButton = findViewById(R.id.market_button);
shopButton.setOnKeyListener(keyListener);
// Hide the tab bar until we measure
mTabsContainer.setAlpha(0f);
onFinishInflate回调函数里面执行了创建TabHost需要的Tab View,这个函数在View加载完配置文件的时候会执行。除了创建TabHost外,还有几个函数需要注意了解。
3、Tab变化时执行onTabChanged
&在TabHost切换选项的时候,会执行onTabChanged回调函数,这里执行了切换页面的操作,具体切换其实是切换AppsCustomizedPagedView类里面的切换,因为所有应用和Widget都是依靠AppsCustomizedPagedView来显示。onTabChanged里面有两个地方需要注意一下:
//Edited by mythou//
public void onTabChanged(String tabId)
    //使用Runnable执行一个切换的动画效果,因为切换的时候会存在数据加载导致的延时问题。    //在加载切换数据的过程中,加入动画可以增强用户体验 mythou
post(new Runnable()
public void run()
ArrayList&View& visiblePages = new ArrayList&View&();
for (int i = visiblePageRange[0]; i &= visiblePageRange[1]; i++)
visiblePages.add(mAppsCustomizePane.getPageAt(i));
//保证每个页面都是使用统一的动画效果
mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), 0);
// mAppsCustomizePane显示子页面是使用相反的顺序,所以添加页面动画的时候,
//也是使用相反的添加顺序
for (int i = visiblePages.size() - 1; i &= 0; i--)
View child = visiblePages.get(i);
            //增加切换动画缓存,提供下面切换动画使用
mAnimationBuffer.addView(child, p);
// Toggle the new content
onTabChangedStart();
onTabChangedEnd(type);
//过渡动画开始
ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, &alpha&, 0f);
         //。。。。。。。。
onTabChanged主要是提供了一个切换页面的动画,以为切换TabHost的时候,会存在一个加载和切换数据的过程,这个过程需要消耗一定时间,所以开了一个线程来执行一个过渡动画,增强用户体验。Launcher里面很多切换操作都存在类似的操作,每个操作都伴随着一个动画效果。主要目的就是让用户觉得界面操作流畅。
4、onLauncherTransitionStart和onLauncherTransitionEnd
&这两个方法是在Launcher.java类里面调用的,具体调用时机就是从workspace切换到AllAPP列表的时候,切换前会调用onLauncherTransitionStart方法,切换后也会调用onLauncherTransitionEnd。看名字我们大概也能猜出这两个方法的作用,也是提供一个过渡的动画效果。onLauncherTransitionEnd还会调用提示界面。
今天就讲到这里,下次会开始进入AppsCustomizedPagedView分析。
Launcher分析系列文章:
Edited by mythou
原创博文,转载请标明出处:&
&&script type=&text/javascript&&&!--
google_ad_client = &ca-pub-8447&;
/* cnblogs 首页横幅 */
google_ad_slot = &&;
google_ad_width = 728;
google_ad_height = 90;
//--&&/script&&script type=&text/javascript& src=&/pagead/show_ads.js&&&/script&
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:9666238次
积分:99074
积分:99074
排名:第10名
原创:361篇
转载:4760篇
译文:17篇
评论:1794条
文章:21篇
阅读:50446
文章:15篇
阅读:38412
文章:22篇
阅读:212927
(4)(8)(28)(21)(47)(1)(1)(8)(170)(814)(1012)(1351)(969)(262)(207)(2)(3)(2)(61)(19)(2)(28)(22)(37)(1)(3)(4)(6)(9)(10)(26)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'}

我要回帖

更多关于 chrome扩展及应用开发 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信